一道關於孩子分糖的問題!!迴圈鍊錶實現

2021-05-25 01:11:38 字數 3117 閱讀 4501

#include

#include

typedef struct cnode

cylist;

#define  size_of_node sizeof(struct cnode)

void init_clist(cylist **list);

void create_clist(cylist **list);

void disp_clist(cylist *list);

int  is_success(cylist **list);

void process_clist(cylist **list);

int main()

void init_clist(cylist **list)

(*list)->next = null;

}void create_clist(cylist **list)

;cylist *head = *list, *curnode = null;

int len = sizeof(array) / sizeof(*array);

int i = 0;

for(i = 0; i < len; ++i)

(*list) = (*list)->next;

head->next = (*list);

}void disp_clist(cylist *list)

printf("%d", node->data);

printf("/n");}}

int is_success(cylist **list)

while(nextnode->next!= *list)

head = head->next;

nextnode = nextnode->next;

}if(nextnode->next == *list)

}return 1;

}void process_clist(cylist **list)

(*list) = curnode; //處理頭結點

(*list)->data = ((curnode->data + key) % 2 ) == 1 ? (curnode->data  + key) / 2 + 1 : (curnode->data  + key) / 2;

printf("after %dth adjust this cylist is : /n", count);

disp_clist(*list);

++count;

}else} }

/*the cycle list you created is :

10-->2-->8-->22-->16-->4-->10-->6-->14-->20

after 1th adjust this cylist is :

15-->6-->5-->15-->19-->10-->7-->8-->10-->17

after 2th adjust this cylist is :

16-->11-->6-->11-->18-->15-->9-->8-->9-->14

after 3th adjust this cylist is :

15-->14-->9-->9-->15-->17-->13-->9-->9-->12

after 4th adjust this cylist is :

14-->15-->12-->10-->13-->17-->16-->12-->10-->11

after 5th adjust this cylist is :

13-->15-->14-->11-->12-->16-->17-->14-->11-->11

after 6th adjust this cylist is :

12-->15-->15-->13-->12-->14-->17-->16-->13-->12

after 7th adjust this cylist is :

12-->14-->16-->15-->13-->13-->16-->17-->15-->13

after 8th adjust this cylist is :

13-->13-->15-->16-->15-->14-->15-->17-->17-->15

after 9th adjust this cylist is :

14-->14-->15-->16-->16-->15-->15-->17-->18-->17

after 10th adjust this cylist is :

16-->14-->15-->16-->16-->16-->16-->17-->18-->18

after 11th adjust this cylist is :

17-->15-->15-->16-->16-->16-->16-->17-->18-->18

after 12th adjust this cylist is :

18-->17-->16-->16-->16-->16-->16-->17-->18-->18

after 13th adjust this cylist is :

18-->18-->17-->16-->16-->16-->16-->17-->18-->18

after 14th adjust this cylist is :

18-->18-->18-->17-->16-->16-->16-->17-->18-->18

after 15th adjust this cylist is :

18-->18-->18-->18-->17-->16-->16-->17-->18-->18

after 16th adjust this cylist is :

18-->18-->18-->18-->18-->17-->16-->17-->18-->18

after 17th adjust this cylist is :

18-->18-->18-->18-->18-->18-->17-->17-->18-->18

after 18th adjust this cylist is :

18-->18-->18-->18-->18-->18-->18-->18-->18-->18

press any key to continue

*/

一道關於迷宮的佇列問題

include include define max n 10 define max m 10 using namespace std const int inf 100000000 使用typedef會更加方便一點 typedef pairp 輸入 char maze max n max m 1 ...

一道C 關於「棧」的問題

void test find 問題是 上述 的執行結果是,兩次顯示 ntempa的結果為123 通過實現test find函式中的 讓第二次的ntempa結果為456 知識點一 棧 乙個程序中的棧空間大小在windows上預設為1m,當然可以通過visualstudio配置 棧的應用範圍是相對於執行...

鍊錶的游標實現 一道演算法題

輸入包含多組資料。每組資料佔一行,包含不超過100000個字母 下劃線 字元 或 者 其中字元 表示home鍵,表示end鍵。輸入結束標誌為檔案結束符 eof 輸 入檔案不超過5mb。對於每組資料,輸出一行,即螢幕上的悲劇文字。樣例輸入 this is a beiju text 樣例輸出 beiju...