// 主函数-用于测试 int main() { // 初始化链表 linkList list = initLinkList(); // 插入三个元素 inserts(&list, 333); inserts(&list, 222); inserts(&list, 2222); // 遍历链表 lists(&list); // 求列表中元素个数 printf("size = %d\n", list.size); // 获取列表中的元素 printf("value = %d\n", getElement(&list, 0)); printf("value = %d\n", getElement(&list, 1)); printf("value = %d\n", getElement(&list, 2)); // 删除列表中的元素 deletes(&list, 2); printf("value = %d\n", getElement(&list, 0)); printf("value = %d\n", getElement(&list, 1)); // 查看最终列表中元素个数 printf("size = %d\n", list.size); }
void managements()//学生信息管理主函数 { struct student * incouse; int i,num2; printf("\t\t\t学生信息管理\n"); printf("1.新增学生信息\n"); printf("2.删除学生信息\n"); printf("3.返回主菜单\n"); printf("请选择(1~3):\n"); scanf("%d",&i); switch(i) { case(1): { incouse=(struct student *)malloc(sizeof(struct student)); incouse->nelen=0; incouse->nelenum[0]=0; printf("学生学号\t学生姓名\n"); scanf("%d%s",&incouse->num2,incouse->name2); inserts(incouse); break; } case(2): { printf("请输入要删除学生的学号:\n"); scanf("%d",&num2); dels(num2); break; } case(3):break; } }
void main () { listnodeptr startptr = NULL; listnodeptr currentptr; listnodeptr abc; int y; int x=0; int z; int id; char xyz[20]; instructions (); printf ("\n\nEnter your choice = "); scanf ("%d", &x); while (x!=4) { inserts (&startptr); x++; } printlist (startptr); // abc = search (startptr); // update (abc); // printlist (startptr); // deletes (startptr); // printf ("\n\nEnter the details of the node you want to add at the end of the list\n"); // inserts(&startptr); // printf ("\n\nEnter name and id of the patient with blank information"); // inserts_blank (&startptr); //insert blank // printlist (startptr); // abc = search (startptr); // update (abc); // printlist (startptr); // printf ("\n\nGoing to delete all the patient with appointments with doctor B\n\n"); // getch(); // search_by_doc (startptr); // printlist (startptr); // insert_in (startptr); printf ("\n\nGoing to delete the whole list\n\n"); deletes_all (startptr); }
void qsort(int * arr, int begin, int end) { if (begin + 10 < end) { int t = div(arr, begin, end); qsort(arr, begin, t - 1); qsort(arr, t, end); } else inserts(arr, begin, end); }
int main() { int c; struct node *head; head=(struct node *)malloc(sizeof (struct node)); while(1) { printf("Enter a choice\n"); printf("1)Create:\n2)View:\n3)Insert Begining:\n4)Insert Specific:\n5)Insert End:\n6)Sort\n"); scanf("%d",&c); switch(c) { case 1: { create(head); break; } case 2: { view(head); break; } case 3: { insertb(head); break; } case 4: { inserts(head); break; } case 5: { inserte(head); } case 6: { sort(head); } } } return 0; }
/*-----------------------------------------------------------------------*/ void main() { int a; clrscr(); inserts(a); inserts(a); inserts(a); inserts(a); inserts(a); inserts(a); display(); deletes(); display(); deletes(); display(); deletes(); display(); inserts(a); inserts(a); display(); getch(); }
static char *find_corrections(char *word) { char **possibles = allocate_possibles(strlen(word)); char *result; int index = 0; if (possibles == NULL) { fprintf(stderr, "cannot allocate the array of possibles"); exit(EXIT_FAILURE); } /* construires une liste de mots possibles */ index = deletions(word, possibles, index); index = transpositions(word, possibles, index); index = alterations(word, possibles, index); index = inserts(word, possibles, index); /*choisir le meilleur candidat entre word et les mots possibles */ result = better_candidate(word, possibles, index); /* un peu de ménage avant de renvoyer le meilleur candidat */ destroy_possibles(possibles, index); return result; }
main(void) { int ch,e,pos,temp=0,ct=1,end=FALSE; list = NULL; LINK *x; LINK *p; // Creating a Header Node (Info part contains number of elements) // // List points to Header Node // p = getnode(); p->info = 0; p->right = p; p->left = p; list = p; while(1) { system("cls"); printf("\n\n\nHeader Doubly Circular Linked List Implementation Using Dynamic Variables\n\n"); printf("1. Insert Elements\n"); printf("2. Delete Elements\n"); printf("3. Display Elements\n"); printf("4. Exit\n\n"); printf("Enter Choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter Element:"); scanf("%d",&e); if(emptys()) pushs(e); else { printf("\nEnter Element Position:"); scanf("%d",&pos); if(pos>count+1 || pos<=0) printf("\nIncorrect Position!"); else inserts(e,pos); fflush(stdin); getchar(); } break; case 2: ct=1; if(emptys()) { printf("\nUnderflow!"); fflush(stdin); getchar(); } else { printf("\nEnter Element to Delete:"); scanf("%d",&e); x=list; while(end == FALSE) // only 1 condition required since LL always contains Header Node { x = x->right; if(x->info==e) { if(x!=list->right) // list.next is first node temp = deletes(x); // Previous Node // else temp=pops(); printf("\n%d Deleted at Position %d !",temp, ct); } if(x->right==list) { x=list; end = TRUE; } ct++; } end = FALSE; if(x==list && temp==0) printf("\nElement Does Not Exist"); fflush(stdin); getchar(); } break; case 3: x = list->right; if(!emptys()) printf("\nLinked List(Number of Nodes:%d):",list->info); while(end==FALSE && !emptys()) { printf("%d->",x->info); x = x->right; if(x==list) end = TRUE; } end = FALSE; if(emptys()) printf("\nLinked List Empty!"); fflush(stdin); getchar(); break; case 4: exit(0); // returning 0 means successful } } }
main(void) { pq.front=pq.rear=NUL; int ch,e,x; int i; // Initialising the pool of available nodes // for(i=0;i<SIZE-1;i++) l[i].next=i+1; l[SIZE-1].next=NUL; while(1) { system("cls"); printf("\n\nPriority Queue Implementation using Linked List Implemented Using Arrays\n\n\n"); printf("1. Insert Element\n"); printf("2. Remove Smallest Element\n"); printf("3. Remove Largest Element\n"); printf("4. Display Elements\n"); printf("5. Exit\n\n"); printf("Enter Choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\n\nEnter Element:"); scanf("%d",&e); inserts(&pq,e); break; case 2: x=pq.front; if(x==NUL) { printf("\nUnderflow!"); fflush(stdin); getchar(); } else { printf("\nFront: %d", l[pq.front].info); x = removesS(&pq); printf("\n\n Deleted !", x); fflush(stdin); getchar(); } break; case 3: x=pq.front; if(x==NUL) { printf("\nUnderflow!"); fflush(stdin); getchar(); } else { printf("\nRear: %d", l[pq.rear].info); x = removesL(&pq); printf("\n\n Deleted !", x); fflush(stdin); getchar(); } break; case 4: x=pq.front; if(x!=NUL) { printf("\nPriority Queue: "); while(x!=NUL) { printf("%d->",l[x].info); x = l[x].next; } } else printf("\nQueue Empty"); fflush(stdin); getchar(); break; case 5: exit(1); } } }
int main(void) { printf("初始化LinkedList及其正反两个方向的迭代器..."); al = list_create(string, LinkedList, NULL); fwd = list_iterator(al, Forward); bwd = list_iterator(al, Reverse); printf("Ok!\n"); printf("TEST1:空列表时的查询\n"); show(); cont(); printf("TEST2: 用append添加一个元素\n"); appends(1); show(); cont(); printf("TEST3: 用remove_at删除一个元素\n"); printf("删除了%zu个元素\n", list_remove_at(al, 0)); show(); cont(); printf("TEST4: 用insert从头部开始连续添加18个元素\n"); inserts(18, 0); show(); int pos = 0; int from = -1; while ((pos = list_search(al, from, Forward, "South Korea", string, 11)) != -1) { printf("正向搜索所有韩国: %d\n", pos); from = pos + 1; } from = -1; while ((pos = list_search(al, from, Reverse, "Brazil", string, 6)) != -1) { printf("反向搜索所有巴西: %d\n", pos); from = pos - 1; } cont(); printf("TEST5: 用remove删除所有Brazil\n"); list_remove(al, "Brazil", string, 6); show(); cont(); printf("TEST6: 用removeall删除所有元素\n"); list_removeall(al); show(); cont(); printf("TEST7: 用push连续添加12个元素后进行递增快速排序\n"); int i, j; for (i = 0; i < 12; i++) { j = rand() % 16; list_push(al, nations[j], string, strlen(nations[j])); } printf("排序前:\n"); type(); printf("排序后:\n"); list_qsort(al, Asc); type(); printf("二分搜索找韩国: %d\n", list_bi_search(al, "South Korea", string, strlen("South Korea"))); printf("二分搜索找中国: %d\n", list_bi_search(al, "中华人民共和国", string, strlen("中华人民共和国"))); cont(); printf("TEST8: 用enqueue连续添加12个元素后进行递减插入排序\n"); for (i = 0; i < 12; i++) { j = rand() % 16; list_enqueue(al, nations[j], string, strlen(nations[j])); } printf("排序前:\n"); type(); printf("排序后:\n"); list_isort(al, Desc); type(); printf("二分搜索找日本: %d\n", list_bi_search(al, "Japan", string, 5)); printf("二分搜索找台湾: %d\n", list_bi_search(al, "中华民国", string, strlen("中华民国"))); printf("反向排列所有元素\n"); list_reverse(al); type(); printf("二分搜索找韩国: %d\n", list_bi_search(al, "South Korea", string, strlen("South Korea"))); printf("二分搜索找中国: %d\n", list_bi_search(al, "中华人民共和国", string, strlen("中华人民共和国"))); printf("二分搜索找日本: %d\n", list_bi_search(al, "Japan", string, 5)); printf("二分搜索找台湾: %d\n", list_bi_search(al, "中华民国", string, strlen("中华民国"))); cont(); printf("TEST9: 用迭代器迭代删除所有元素\n"); Iterator delit = list_iterator(al, Forward); Element ele = NULL; while ((ele = it_next(delit))) { it_remove(delit); printf("删除元素:\"%s\"\n", POINTOF(ele, char)); free(ele); } type(); cont(); printf("TEST10: 模拟堆栈\n"); printf("连续PUSH三次:\n"); j = rand() % 16; list_push(al, nations[j], string, strlen(nations[j])); type(); j = rand() % 16; list_push(al, nations[j], string, strlen(nations[j])); type(); j = rand() % 16; list_push(al, nations[j], string, strlen(nations[j])); type(); printf("用stacktop读取栈顶元素:"); ele = list_stacktop(al); printf(" \"%s\"\n", POINTOF(ele, char)); free(ele); printf("用pop弹空堆栈:\n"); ele = list_pop(al); printf("\"%s\"\n", POINTOF(ele, char)); free(ele); ele = list_pop(al); printf("\"%s\"\n", POINTOF(ele, char)); free(ele); ele = list_pop(al); printf("\"%s\"\n", POINTOF(ele, char)); free(ele); type(); cont(); printf("TEST11: 模拟队列\n"); printf("连续enqueue三次:\n"); j = rand() % 16; list_enqueue(al, nations[j], string, strlen(nations[j])); type(); j = rand() % 16; list_enqueue(al, nations[j], string, strlen(nations[j])); type(); j = rand() % 16; list_enqueue(al, nations[j], string, strlen(nations[j])); type(); printf("用queuehead读取栈顶元素:"); ele = list_queuehead(al); printf(" \"%s\"\n", POINTOF(ele, char)); free(ele); printf("用dequeue全部出队:\n"); ele = list_dequeue(al); printf("\"%s\"\n", POINTOF(ele, char)); free(ele); ele = list_dequeue(al); printf("\"%s\"\n", POINTOF(ele, char)); free(ele); ele = list_dequeue(al); printf("\"%s\"\n", POINTOF(ele, char)); free(ele); type(); cont(); printf("TEST12: 两个列表相加\n"); Container list2 = list_create(string, LinkedList, NULL); appends(9); printf("原列表:\n"); type(); printf("加上一个空列表:\n"); list_plus(al, list2); type(); printf("加上一个有9个元素的列表:\n"); for (i = 0; i < 9; i++) { j = rand() % 16; list_append(list2, nations[j], string, strlen(nations[j])); } list_plus(al, list2); type(); cont(); printf("再减去这个列表:\n"); list_minus(al, list2); type(); printf("再减去一个空列表:\n"); Container empty = list_create(string, LinkedList, NULL); list_minus(al, empty); type(); cont(); printf("添加到18个元素后再进行retain操作,类似取交集\n"); appends(18); printf("原列表:\n"); type(); printf("list2:\n"); for (i = 0; i < 9; i++) { ele = list_get(list2, i); printf("%s, ", POINTOF(ele, char)); free(ele); } printf("\n"); list_retain(al, list2); printf("retain后:\n"); type(); printf("retain一个空列表:\n"); list_retain(al, empty); type(); printf("FIN: 销毁列表和迭代器..."); it_destroy(fwd); it_destroy(bwd); list_destroy(al); list_destroy(list2); list_destroy(empty); printf("Ok!\n"); return 0; }
main(void) { int ch,e,pos,temp=0,ct=1; LINK *x; LINK *y; list=NULL; while(1) { system("cls"); printf("\n\n\nDoubly Linked List Implementation Using Dynamic Variables\n\n"); printf("1. Insert Elements\n"); printf("2. Delete Elements\n"); printf("3. Display Elements\n"); printf("4. Exit\n\n"); printf("Enter Choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter Element:"); scanf("%d",&e); if(emptys()) pushs(e); else { printf("\nEnter Element Position:"); scanf("%d",&pos); if(pos>count+1 || pos<=0) printf("\nIncorrect Position!"); else inserts(e,pos); fflush(stdin); getchar(); } break; case 2: ct=1; if(emptys()) { printf("\nUnderflow!"); fflush(stdin); getchar(); } else { printf("\nEnter Element to Delete:"); scanf("%d",&e); x=list; while(x!=NULL) { if(x->info==e) { if(x!=list) temp = deletes(x); // Current Node // else temp = pops(); printf("\n%d Deleted at Position %d !",temp, ct); } x=x->right; ct++; } if(x==NULL && temp==0) printf("\nElement Does Not Exist"); fflush(stdin); getchar(); } break; case 3: x = list; if(list!=NULL) printf("\nLinked List:"); while(x!=NULL) { printf("%d->",x->info); x = x->right; } if(list==NULL) printf("\nLinked List Empty!"); fflush(stdin); getchar(); break; case 4: exit(0); // returning 0 means successful } } }