int main (void) { Node *root; root = (Node *)malloc(sizeof(Node)); create(root); printf("length is :%d\n", getListNodeNum(root)); my_list(root); root = sll_reverse(root); my_list(root); }
int main() { std::unique_ptr <App> my_list(new App()); std::unique_ptr <Solution> mySolution(new Solution()); std::unique_ptr <InsertToHead> insertToHead(new InsertToHead()); try { long a1 = std::clock(); std::cout << "Time Start: " << a1 << "\n"; // my_list->Run(); // mySolution->Run(); insertToHead->Run(); long b1 = std::clock(); std::cout << "Time END: " << b1 << "\n\n"; std::cout << "Open file Time TOTAL: " << (b1-a1)/1000.0 << " sec.\n"; } catch(std::runtime_error) { std::cout << "EXCEPTION_EXECUTE_HANDLER\n"; } /* __except (EXCEPTION_EXECUTE_HANDLER) { std::cout << "EXCEPTION_EXECUTE_HANDLER has number - " << EXCEPTION_EXECUTE_HANDLER << "\n"; } */ //std::string p; system("PAUSE"); //std::cout << "\nPress any key to exit...\n"; //cin >> p; return 1; }
int main() { int my_array[]={1,2,3,4,5}; std::list<int> my_list(my_array, my_array+sizeof(my_array)/sizeof(int)); std::list<int>::iterator iter=my_list.begin(); // ++ operator basically does what ->next does in your data-structure for(int i=0; i<2; i++) iter++; // Now iter points to 3 std::cout<<*iter<<std::endl; /*To delete this, we have to swap it with the next element. I had noted earler also that swapping is mostly feasible in LL when the nodes are nearby.*/ /*Swap data between the current node and the next node.*/ std::list<int>::iterator next_node=iter; ++next_node; int temp=*iter; *iter=*next_node; *next_node=temp; my_list.erase(next_node); for(std::list<int>::iterator it=my_list.begin(); it!=my_list.end(); ++it) { std::cout<<*it<<std::endl; } }
void my_display(){ //if(!if_draw) return; glClearColor(0.5,0.2,0.5,1.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); /*glBegin(GL_POINTS); glVertex2f(0.0,0.0); glEnd(); glFlush();*/ //printf("%d \n",if_draw); if(trackballMove) glRotatef(angle,axis[0],axis[1],axis[2]); my_list(); //glLoadIdentity(); /*for(unsigned int i=0;i<my_rwfile->GetTriNum();i++){ glBegin(GL_TRIANGLES); for(unsigned int j=0;j<3;j++){ glColor3f(0.0,0.2,0.5); glNormal3dv((*my_rwfile)[(*my_rwfile)(i).tri_vtx[j]-1].vtx_nrm); glVertex3d((*my_cg)[(*my_rwfile)(i).tri_vtx[j]-1][0],(*my_cg)[(*my_rwfile)(i).tri_vtx[j]-1][1],(*my_cg)[(*my_rwfile)(i).tri_vtx[j]-1][2]); } glEnd(); }*/ //my_draw(); glCallList(list_id); glutSwapBuffers(); glFlush(); }
void exec_comm(int cl){ int size,j=0,i=0, port; char buff[1024], *param,*command, *param1,*filename; char commands[100],buff2[200],dir[200]; fd_set fds; memset(buff, '\0', 1024); if((recv(clients[cl]->sock, buff, sizeof(buff), 0))<0){ perror("error in Receiving"); exit(1); } printf("%s\n",buff); command = strtok (buff," "); //buff[size-2]=0; // -'\r' et -'\n' /*while(buff[j]){ param[i]=buff[j+1]; i++;j++; }*/ //param = strchr(buff," "); // param <- commande param = strtok (NULL, " "); for (j = 0; j < strlen(command); j++) command[j]=toupper(command[j]); printf("%s\n",command); printf("%s\n",param); for (j = 0; j < 8; j++) if (!strcmp(command,commandes[j])) break; switch(j){ case QUIT: if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM); clients[cl]->pid=0; close(clients[cl]->sock); clients[cl]->sock=0; clients[cl]->dataport=0; nb_users--; printf("%s\n", commandes[j]); break; case PORT: port = atoi(param); clients[cl]->dataport = port; printf("%s %s\n", commandes[j], param); send(clients[cl]->sock, ok, strlen(ok)+1, 0); break; case CWD: strcpy(tmp,clients[cl]->curdir); strcat(tmp,"/"); strcat(tmp,param); if(chdir(tmp)<0){ perror("error"); memset(msz,'\0',sizeof(msz)); sprintf(msz,"%s","No Such Directory"); send(clients[cl]->sock, msz, strlen(msz)+1, 0); } else{ memset(clients[cl]->curdir, '\0', (strlen(clients[cl]->curdir)+1)); strcpy(clients[cl]->curdir,tmp); memset(msz,'\0',sizeof(msz)); sprintf(msz,"%s","Directory Changed"); send(clients[cl]->sock, msz, strlen(msz)+1, 0); printf("%s %s\n", commandes[j],clients[cl]->curdir); } prompt(); break; case RGET: //param1 = strtok(param,"-"); //filename = strtok(NULL,"-"); //port = atoi(param1); //clients[cl]->dataport = port; //send(clients[cl]->sock, ok, strlen(ok)+1, 0); // printf("%s %s\n", commandes[j], filename); strcat(commands,"ls -R "); system("ls"); strcat(commands,param); printf("%s",param); system(commands); FILE *fd = popen(commands,"r"); while(fgets(buff, sizeof(buff), fd)!=NULL){ if(buff[(strlen(buff)-1)]==':'){ //strcpy(dir,buff); //printf("%s",dir); memcpy(dir,buff,strlen(buff)-2); if(send(clients[cl]->sock,buff, strlen(buff), 0)<0) perror("Send"); } else{ strcat(dir,"param/"); strcat(dir,buff); strcpy(buff,dir); if(send(clients[cl]->sock,buff, strlen(buff), 0)<0) perror("Send"); } } //rget(cl,param); break; case MGET: strcat(commands,"ls "); //system("ls"); strcat(commands,param); printf("%s",param); //system(commands); fd = popen(commands,"r"); while(fgets(buff, sizeof(buff), fd)!=NULL){ printf("\n%s",buff); if(send(clients[cl]->sock,buff, strlen(buff), 0)<0) perror("Send"); } //rget(cl,param); break; // Since the list of files can be a considerable size, it is better to create a child // Which will deal with the client case LIST: port = atoi(param); printf("%d",port); clients[cl]->dataport = port; if( (clients[cl]->pid = fork()) == 0 ){ send(clients[cl]->sock, ok, strlen(ok)+1, 0); my_list(cl); } //send(clients[cl]->sock, ok, strlen(ok)+1, 0); printf("%s %s\n", commandes[j], clients[cl]->curdir); break; // Because a file can be of great size, it is better to create a child Which will deal with the sending to the client case RETR: param1 = strtok(param,"-"); filename = strtok(NULL,"-"); port = atoi(param1); clients[cl]->dataport = port; if( (clients[cl]->pid = fork()) == 0 ) { send(clients[cl]->sock, ok, strlen(ok)+1, 0); retr(cl, filename); } printf("%s %s\n", commandes[j], param); break; // Because a file can be of great size, it is better to create a child Which will deal with the recovery from the client case STOR: param1 = strtok(param,"-"); filename = strtok(NULL,"-"); port = atoi(param1); clients[cl]->dataport = port; if( (clients[cl]->pid = fork()) == 0 ){ if(send(clients[cl]->sock, ok, strlen(ok)+1, 0)<0) perror("send"); stor(cl, filename); } printf("%s %s\n", commandes[j], param); break; // Because a file can be of great size, it is better to create a child Which will deal with the removal //By default, we consider that if a client sends commands incomprehensible, it must be disconnected default: if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM); if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM); clients[cl]->pid=0; close(clients[cl]->sock); clients[cl]->sock = 0; clients[cl]->dataport = 0; nb_users--; printf("Client %d Disocnnected\n",cl); break; prompt(); } }