// int size = 0; int main() { //Initialize Crcular linked list with NULL head node *head = NULL; int data = 10; // printf("Enter: "); // scanf("%d",&data); insertLast(&head, data); insertFirst(&head, 5); print(&head); printf("Size: %d\n", size(&head)); printf("Insert at position 1\n"); insertAtPosition(&head, 1,1); print(&head); printf("Size: %d\n", size(&head)); printf("Insert at position 4\n"); insertAtPosition(&head, 15,4); print(&head); printf("Size: %d\n", size(&head)); deleteFirst(&head); print(&head); printf("Size: %d\n", size(&head)); deleteLast(&head); print(&head); printf("Size: %d\n", size(&head)); deleteAtPosition(&head,2); print(&head); printf("Size: %d\n", size(&head)); deleteAtPosition(&head,1); print(&head); printf("Size: %d\n", size(&head)); printf("New Circular linked list\n"); node *head1 = NULL; createList(&head1); print(&head1); printf("Enter data want to search: "); scanf("%d", &data); search(&head1,data); printf("Sort a circular linked list\n"); sort(&head1); print(&head1); }
int main() { SCHEDULE *s = NEW(SCHEDULE); FILE *f = NULL; int month,day; int search_month = 1,search_day = 2; /*if((search_month = atoi(argv[2])) ==0 || (search_day = atoi(argv[3])) ==0){ printf("values provided for month and day are not valid\n"); exit(-1); }*/ s->first = NULL; s->last = NULL; f = fopen("test.txt","r"); if(f == NULL){ printf("invalid file \n"); exit(0); } int i =0; while(fscanf(f,"%d/%d",&month,&day)!=-1){ int m = month; int d = day; insertAtPosition(s,m,d); if(i ==3){ break; } i = i+1; } display(s); printf("\n"); printf("\n"); search(s,search_month,search_day); return 0; }
int main(int argc, char *argv[]) { FILE *ft,*fd; while (1) { switch(getmenu("Import DB from NokiaDB.dat;Print data;Insert data;Delete data;Search Data & modify data;Devide list & Extract List;Reverse list;Save to file;Quit",9,0)) { mfflush(); case 1: if((fd = fopen(DAT,"r+b")) == NULL) printf("\t\tCan't read file %s",DAT); else { if(getmenu("Insert Whole;Insert Part",2,0) == 1) { importfdat(fd,1,1); } else { if(getmenu("From Begin;From ending",2,0) == 1) importfdat(fd,2,1); else importfdat(fd,2,2); } printf("\t\tImport DB complete !!\n"); fclose(fd); } break; case 2:if(root == NULL && root2 == NULL) { indent(2); printf("Import data first !!\n"); } else { if(root2 == NULL) printdat(root); else { int c ; if((c = getmenu("Print data of first list;Print data of second list",2,0)) == 1) printdat(root); else printdat(root2); } } break; case 3:if(root == NULL){ indent(2); printf("Import data first !!\n"); } else { int c; VARTYPE p; printf("\t\tModel of phone :");scanf("%[^\n]",p.model);mfflush(); printf("\t\tSize of phone :");scanf("%d",&p.size);mfflush(); printf("\t\tPhone's size of screen :");scanf("%f",&p.screen);mfflush(); printf("\t\tPhone's price :");scanf("%d",&p.price);mfflush(); if((c = getmenu("Insert at Begining;Insert at Ending;Insert at Position",3,0)) == 1) { insertB(p); } else if (c == 2) insertE(p); else { int z; node *g; do { printf("\t\t Where you want to insert (if you don't want to insert anymore input -1 !! 1st = 0 postion) :");scanf("%d",&z);mfflush(); g = insertAtPosition(p,z); } while (g == NULL && z != -1); } }break; case 4:if(root == NULL) { indent(2); printf("Import data first !!\n"); } else { int c; if((c = getmenu("Delete at Postion;Delete current;Delete first",3,0))==1) { int p; printf("\t\t Where you want to delelte (if you don't want to insert anymore input -1 !! 1st = 0 postion) :");scanf("%d",&p);mfflush(); deleteAtPosition(p); } else if(c == 2) delNode(cur); else if(c == 3) delNode(root); } break; case 5: if(root == NULL) { indent(2); printf("Import data first !!\n"); } else { int cc; if((cc = getmenu("Search data;Modify data",2,0)) == 1){ int c; if((c = getmenu("Search By name;Search By Price",2,0)) ==1) search(root,1); else search(root,2); } else { modify(); } } break; case 6: if(root == NULL) { indent(2); printf("Import data first !!\n"); } else { int c; if((c = getmenu("Devide List;Extract list",2,0))==1){ int p; printf("\t\tPostion you want to devide list : ");scanf("%d",&p);mfflush(); root2 = devideList(root,last,p); } else { int p,n; printf("\t\tPostion you want to start extract list : ");scanf("%d",&p);mfflush(); printf("\t\tLength of extract list : ");scanf("%d",&n);mfflush(); extractList(p,n); } }break; case 7:if(root == NULL) { indent(2); printf("Import data first !!\n"); } else { reversel(); }break; case 8:if(root == NULL) { indent(2); printf("Import data first !!\n"); } else { if((fd = fopen(DAT,"w+b")) == NULL) printf("Can't create file %s",DAT); else { exporttdat(fd); } }break; case 9: freelist(root); freelist(root2); indent(2);printf("Exit Program !!\n"); return 0; } } }