t_listgnl *getlist(int fd) { static t_listgnl *begin = NULL; t_listgnl *list; t_listgnl *tmp; if (begin == NULL) { list = createlist(fd); begin = list; return (list); } list = begin; while (list) { if (fd == list->fd) return (list); list = list->next; } tmp = createlist(fd); list = begin; while (list->next) list = list->next; list->next = tmp; return (list->next); }
int main() { np h1,h2; h1=h2=NULL; printf("Enter list 1\n"); h1=createlist(h1); printf("Enter list 2\n"); h2=createlist(h2); printf("Common elements are\n"); comele(h1,h2); return 0; }
int main() { struct node *num1 = createlist(); struct node *num2 = createlist(); printlist(num1); printf("\n"); printlist(num2); printf("\n"); struct node *sum = findsum(num1, num2); printlist(sum); return 0; }
int main(void) { ListPtr list1 = createlist('0'); ListPtr list2 = createlist('A'); showlist(list1); showlist(list2); concatenate(list1, list2); showlist(list1); return 0; } /* E0F main */
void do_output(t_tre *start, t_lid *lemdata) { t_mls *path_start; t_mls *path_end; t_tre *end_room; t_tre *tmp_list; if (start == NULL) return; if ((path_start = createlist(start, NULL)) == NULL) return; start->nb_ants = my_atoi(lemdata->file->next->item); tmp_list = start->parent; while (tmp_list != NULL) { if (tmp_list->parent == NULL) end_room = tmp_list; if (list_pushback(path_start, tmp_list, NULL) == MERROR) return; tmp_list = tmp_list->parent; } path_end = path_start; while (path_end->next != NULL) path_end = path_end->next; while (end_room->nb_ants < lemdata->nb_ants) ant_march(path_end); }
int dtf_setunits(t_dtf *map) { int i; int j; i = -1; if (get_crtreturn(NULL)) return (0); if (map == NULL || map->map == NULL || map->units != NULL) return (dbgerr("Error: dtf_setunits: NULL or invalid parameters")); if ((map->units = createlist(NULL, NULL)) == NULL) return (dbgcrt("Error: dtf_setunits: createlist function returned NULL")); while (++i < map->height && map->map[i] != NULL) { j = -1; while (++j < map->width) { if (ISERRV(map->map[i][j])) return (dbgcrt("Error: dtf_setunits: Invalid value in the map")); else if (ISREDV(map->map[i][j]) || ISBLUE(map->map[i][j])) { if (!dtf_addunit(map, j, i)) return (dbgerr("Error: dtf_setunits: Add unit failed")); } } } return (1); }
void main() { struct node *head,*head1; head1=NULL; int value,n,exit=0; clrscr(); printf("1:createlist \t 2:printlist \t 3:exit"); printf("\n"); while(exit!=1) { printf("\n enter value from menu:"); scanf("%d",&n); switch(n) { case 1: { head=createlist(head); break; } case 2: { printlist(head); break; } case 3: { exit=1; break; } } } getch(); }
int main() { node* headptr;//保存第一个节点的地址 createlist(&headptr); insert(&headptr, 10, 2);//无效位置,会更正成末尾 insert(&headptr, 20, 0);//20,10 insert(&headptr, 30, 2);//20,10,30 insert(&headptr, 40, 1);//20,40,10,30 insert(&headptr, 50, 8);//无效位置,会更正成末尾 travel(headptr); printf("剩余%d个数据\n", listsize(headptr)); int n = find(headptr, 10); printf("查找10在第%d个节点\n", n); erase(&headptr, n); travel(headptr); n = find(headptr, 10); printf("查找10在第%d个节点\n", n); erase(&headptr, n); travel(headptr); setdata(headptr, 10, 100); setdata(headptr, 2, 99); travel(headptr); clear(&headptr); printf("剩余%d个数据\n", listsize(headptr)); return 0; }
int main(void){ int t; int n,a,b,i; int hq1,hq2; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&hq1,&hq2); arr= createlist(n); for(i=1;i<hq1;i++){ scanf("%d",&a); arr[i].add(a); arr[a].add(i); } for(i=hq1+1;i<=n;i++){ scanf("%d",&a); arr[i].add(a); arr[a].add(i); } dfs_visit(hq2); for(i=1;i<hq2;i++) printf("%d ",arr[i].parent); for(i=hq2+1;i<=n;i++) printf("%d ",arr[i].parent); printf("\n"); } return 0; }
main() {list l; createlist(&l); int n,i; char ch,name[10]; printf("choose the foll. options\n1. PUSH\n2. POP\n3. DISPLAY\n"); do {printf("enter the option u want to select\n"); scanf("%d",&n); switch(n) {case 1: printf("enter a name\n"); scanf("%s",name); printf("pushing into the stack\n"); for(i=0;name[i]!='\0';i++) push(name[i],&l); break; case 2: printf("the poped character is:\t"); pop(&ch,&l); putchar(ch); printf("\n"); break; case 3: printf("STACK CONTENTS\n"); display(&l); break; default: printf("enter proper choice\n"); break; }}while(n!=4); }
int main(int argc, char* argv[]){ char *inputFile; FILE *fp; Node *head; if (argc != 2){ fprintf(stderr, "usage: generate <file>\n"); exit(1); } inputFile = argv[1]; fp = fopen(inputFile, "r"); assert(fp != NULL); head = createlist(fp); if (fclose(fp) == EOF){ fprintf(stderr, "closing file failed\n"); exit(1); } playgame(head); return 0; }
main() {list l; createlist(&l); int n,i; char ch,name[10]; printf("choose the foll. options\n1. APPEND\n2. SERVE\n3. DISPLAY\n"); do {printf("enter the option u want to select\n"); scanf("%d",&n); switch(n) {case 1: printf("enter a name\n"); scanf("%s",name); printf("Appending into Queue\n"); for(i=0;name[i]!='\0';i++) append(name[i],&l); break; case 2: printf("Served element in the Queue:\t"); serve(&ch,&l); putchar(ch); printf("\n"); break; case 3: printf("QUEUE CONTENTS\n"); display(&l); break; default: printf("enter proper choice\n"); break; }}while(n!=4); }
void entoce(char *data, char *cedrof) { // Estrutura organizada com os dados struct TDDCData *trade = createlist(); // Separa os dados na estrutura splitcolumns(data, 9, trade); // Dados conhecidos: // T: = Tick de cota��o // B: = Mini book 5 melhores // N: = Negocios realizados // D: = Livro completo // Verifica qual tipo de dado � if (trade->value[0] == 'T') { // Tick de trade entick(trade, cedrof); } else if (trade->value[0] == 'N') { // Altera N para T trade->value[0] == 'T'; // Negocios realizados entrade(trade, cedrof); } // Destroi a lista destroylist(trade); }
main() { node *start; clrscr(); start = createlist(); display(start); getch(); }
/*根据关键字查找备选命令*/ int SearchCmdOption(const char *envpath, const char *text, char cmd_option[cmd_option_nummax][cmd_length], int *option_num) { dirlist=createlist(dirlist); char path[PATH_MAX+1]={'\0'}; strcpy(path,envpath); fillcmdop(path,text,cmd_option,option_num); deletelist(dirlist); return 1; }
int SearchFile(const char *envpath, const char *file, char *filepath) { dirlist=createlist(dirlist); char path[PATH_MAX+1]={'\0'}; strcpy(path,envpath); int finished=myftw(path, file,filepath); deletelist(dirlist); return finished; }
main() { linklist newlist=createlist(N); do { printf("%c",newlist->data); newlist=newlist->next; }while(newlist!=NULL); printf("\n"); }
int main(){ struct ll *head=NULL; createlist(&head); int flag = ifloop(head); if (flag){ printf("There is a loop \n"); printloopstart(head,flag); } return 0; }
list* readfromfile() {///home/pi/wd/sitchart/src/ FILE *rd[4]; rd[0]=fopen("col_0","rb"); rd[1]=fopen("col_1","rb"); rd[2]=fopen("col_2","rb"); rd[3]=fopen("col_3","rb"); list *p=createlist(); for(int i=0;i<4;i++) readone(rd[i],p); return p; }
int main() { int item, n; struct node *head = createlist(); printlist(head); //scanf("%d", &n); deletenode(head->next->next); //printf("%d\n", item); printf("\n"); printlist(head); return 0; }
int main() { Node* head; head=createlist(); assert(head!=NULL); printlist(head); reverselist(&head); printf("after reverse\n"); printlist(head); return 0; }
int main(){ char buf[1024]; Num *op1,*op2,*res; printf("Operand #1 : "); scanf("%[0-9]*",buf); op1=createlist(buf); getchar(); printf("Operand #2 : "); scanf("%[0-9]*",buf); op2=createlist(buf); res=numadd(op1,op2); printlist(op1); printf("\n + \n"); printlist(op2); printf("\n = \n"); printlist(res); printf("\n"); deletelist(op1); deletelist(op2); deletelist(res); return 0; }
int main() { int x[6]={3,6,5,2,8,9},a,c,d,e=8,g; bool b,f; sqlist *A; createlist(A,x,6); listinsert(A,4,1); listdelete(A,2,g); displist(A); a=listlength(A); b=getelem(A,3,c); d=locateelem(A,e); printf("%d\n",a); printf("%d\n",b); printf("%d\n",d); printf("%d\n",f); system("pause"); return 0; }
/*-------------------------------------------------------------------*/ void main() { int a; clrscr(); createlist(a); addnode(a); addnode(a); addnode(a); display(); inserthead(a); display(); inserttail(a); display(); delhead(); display(); deltail(); display(); getch(); }
void testcases() { int lv1,median=0; for(lv1=0;lv1<6;lv1++) { nodetype *head; head=createlist(test[lv1].input); median=Median(head); if(test[lv1].output==median) {} else { printf("test%d is failed",lv1+1); return ; } //display(head); } printf("tests are passed"); return ; }
int main(int argc, const char * argv[]) { FILE * file; const char *inputfile; if(argc != 2){ /*We print argv[0] for the program name */ printf("usage: game2 <file>\n"); exit(1); } inputfile = argv[1]; /* Assuming filename is containedin argv[1]*/ file = fopen(inputfile, "r"); /*open returns 0 if file is unopened*/ if(file == -1){ printf("Could not open file\n"); exit(1); } playgame(createlist(file)); }
int main() { int n,i=0; dlinklist *L; void createlist(dlinklist *&L,int n); void sort(dlinklist *&L); scanf("%d",&n); createlist(L,n); sort(L); while(L->next!=NULL) { if(i==0) { printf("%d",L->next->data); } else printf(" %d",L->next->data); L=L->next; i++; } return 0; }
void endgame(void) /* count pieces and announce the winner */ { char an[10]; int i, j, k, N, mtot, utot, cont; int mymovelist[NODES][5]; int umovelist[NODES][5]; printf("\nTo count score, we need the following steps:\n"); printf("First, I need you to remove all dead pieces on the board.\n"); printf("Second, I need you to fill in neutral territories with "); printf("pieces.\n"); printf("Last, I will fill in all pieces and announce the winner.\n"); /* remove dead pieces */ printf("\nFirst, you should enter the dead pieces (black and white) to"); printf(" be removed. Enter\n"); printf(" 'stop' when you have finished.\n"); /* Create an adjacency list for the game board. */ /* First a list for the computer's moves */ createlist(mymove, mymovelist); /* Then a list for our opponent's moves */ createlist(umove, umovelist); cont = 1; do { printf("Dead piece? "); scanf("%s", an); if (strcmp(an, "stop")) { getij(an, &i, &j); if (p[i][j] == mymove) { #ifdef DEBUG printf("Just before bfslist.\n"); #endif N = bfslist(i, j, mymovelist, listpt); #ifdef DEBUG printf("Survived first bfslist.\n"); #endif for (k=0;k<N;k++) { node2ij(listpt[k], &i, &j); p[i][j] = EMPTY; mk++; } } else if (p[i][j] == umove) { #ifdef DEBUG printf("Just before second bfslist.\n"); #endif N = bfslist(i, j, umovelist, listpt); for (k=0;k<N;k++) { node2ij(listpt[k], &i, &j); p[i][j] = EMPTY; uk++; } } showboard(); } else cont = 0; } while (cont); /* fill in neutral */ printf("Next, you need to fill in pieces (black and white) in all neutral"); printf(" territories.\n"); printf("Enter your and my pieces alternately and"); printf(" enter 'stop' when finish\n"); cont = 1; N = 0; do { if ( (N%2) == 0 ) { printf("Your piece? "); scanf("%s", an); if (strcmp(an, "stop")) { getij(an, &i, &j); p[i][j] = umove; showboard(); } else cont = 0; } else { printf("My piece? "); scanf("%s", an); if (strcmp(an, "stop")) { getij(an, &i, &j); p[i][j] = mymove; showboard(); } else cont = 0; } N++; } while (cont); /* set empty to side they belong to */ for (i = 0; i < 19; i++) for (j = 0; j < 19; j++) if (p[i][j] == EMPTY) p[i][j] = findcolor(i, j); /* count total */ mtot = 0; utot = 0; for (i = 0; i < 19; i++) for (j = 0; j < 19; j++) if (p[i][j] == mymove) ++mtot; else if (p[i][j] == umove) ++utot; showboard(); printf("Your total number of pieces %d\n", utot); printf("My total number of pieces %d\n", mtot); } /* end endgame */
void start() { char ch,ch1; loads(); cout<<"\t\t\t\t\t\t\tWELCOME TO MANAGER MODE\n\t\t\t\t\t\t\t_______________________\n\n\n"; createlist(); chooseteam(); createplayerlist(); cout<<"\nPlease enter the manager details\n\n"; t[I].get2(); cout<<"\n\nTEAM AND MANAGER DETAILS\n________________________\n\n"; t[I].disp3(); t[I].disp1(); t[I].disp2(); cout<<"\nAre you ready to begin(y/n):"; cin>>ch; cout<<"\n\n\nPLAYER LIST\n___________\n\n"; if(ch=='y') { displaylist(); chooseplayers(); if(t[I].rem<=0) { cout<<"\n\nOOPS!! You are out of cash\n YOU'RE FIRED FROM THE JOB"; cout<<"\nDo you want to try again (y/n):"; cin>>ch; if(ch=='y') { system("cls"); for(int k=0;k<8;k++) { t[k].rem=60000; t[k].points=0; t[k].w=0; t[k].l=0; t[k].d=0; } main(); } else if(ch=='n') exit(0); else { cout<<"Invalid.Enter again:"; cin>>ch; if(ch=='y') { system("cls"); for(int k=0;k<8;k++) { t[k].rem=60000; t[k].points=0; t[k].w=0; t[k].l=0; t[k].d=0; } main(); } else if(ch=='n') exit(0); } }
int main() { //clrscr(); int n=1,l=0,choice; printf("enter how many elements u want to enter\n\t"); scanf("%d",&n); head=createlist(n); while(1) { printf("\n1.insert at begning"); printf("\t2 insert at last"); printf("\t3 insert at position"); printf("\n4 display"); printf("\t5 search"); printf("\t6 delete at specfic position"); printf("\n7 delete at last\t"); printf("\t8 delete at begning"); printf("\t9 swap"); printf("\n10 conactenate lists"); printf("\n11 exit\t"); scanf("%d",&choice); switch(choice) { case 1: inatbeg(); displaylist(head); break; case 2: inlast(); displaylist(head); break; case 3: nyp(); displaylist(head); break; case 4: displaylist(head); break; case 5: l=search(head); if(l!=-1) printf("\t\t key found at position %d \t",l); else printf("\t\t sory value not found \n"); break; case 6: int p; printf("\n enter positi0n to delete\t"); scanf("%d",&p); dnode(p); displaylist(head); break; case 7: dlast(); displaylist(head); break; case 8: dbeg(); break; case 9: swap(head); displaylist(head); break; case 10: //concatenate(); break; case 11: exit(0); break; deafault: printf("\n enter valid choice\n"); } } getch(); }