void main() { int a[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; int i; struct List L; initList(&L, 5); for(i = 0; i < 10; i++){ insertLastList(&L, a[i]); } insertPosList(&L, 11, 48); insertPosList(&L, 1, 64); printf("%d ", getElem(&L, 1)); traverseList(&L); printf("%d ", findList(&L, 10)); updatePosList(&L, 3, 20); printf("%d ", getElem(&L, 3)); traverseList(&L); deleteFirstList(&L); deleteFirstList(&L); deleteLastList(&L); deleteLastList(&L); deletePosList(&L, 5); ;deletePosList(&L, 7); printf("%d ", sizeList(&L)); printf("%d ", emptyList(&L)); traverseList(&L); clearList(&L); return 0; }
int compareListWithGivenResultFile(SqList listToTest, FILE *resultFin) { SqList list = setupLinearListUsingFile(resultFin); ElemType *resultArr = traverseList(list); ElemType *listToTestArr = traverseList(listToTest); *resultArr = 0; *listToTestArr = 0; return OK; }
int main() { node *head = (node *)(malloc(sizeof(node))); node *second = (node *)(malloc(sizeof(node))); node *third = (node *)(malloc(sizeof(node))) ; node *fourth = (node *)(malloc(sizeof(node))) ; head->data = 1; head->next = second; second->data = 2; second->next = third; third->data = 3; third->next = fourth; fourth->data = 4; fourth->next = NULL; if(traverseList(head) == -1) { printf("List is empty"); return -1; } return 0; }
int main() { // monitor analysis center,update the gloable variable uploadList, is always running pthread_t analysisCenterMonitorTread; // start up uoload function,transfer data from analysis center to products&service center pthread_t uploadTread; // log file uploading or downloading action state whether success or failed pthread_t logTread; // the most important thread, the other is actived by it,expect analysisCenterMonitorTread. pthread_t timingTaskTread; config("system.ini"); traverseList(); initUploadlist(); //create seven threads,but never destroy them. { //create the thread analysis Center Monitor pthread_create(&analysisCenterMonitorTread,NULL,analysisCenterMonitor,(void *)NULL); //create the thread upload pthread_create(&uploadTread,NULL,upload,(void *)NULL); //create the thread upload pthread_create(&logTread,NULL,log,(void *)NULL); //create the thread timing task pthread_create(&timingTaskTread,NULL,timingTask,(void *)NULL); } while(1); }
int main() { nodeT *root=createBinTree(); nodeL *firstFromList=getListFromTree(root); traverseList(firstFromList); printf("\n"); prettyPrint(root,0); return 0; }
int main(void) { void traverseList(struct entry *listPointer); void removeEntry(struct entry *listPointer); void insertEntry(struct entry *listPointer, struct entry *entryPointer); struct entry n1, n2, n3; struct entry *startListPointer = &n1; struct entry *lastListPointer = &n3; struct entry *n2Pointer = &n2; n1.value = 100; n1.previous = (struct entry *) 0; n1.next = &n2; n2.value = 200; n2.previous = &n1; n2.next = &n3; n3.value = 300; n3.previous = &n2; n3.next = (struct entry *) 0; printf("First element to last traversal:\n"); traverseList(startListPointer); printf("\n"); printf("Last element to first traversal:\n"); traverseList(lastListPointer); printf("\n"); removeEntry(n2Pointer); printf("Traversal after removal of n2:\n"); traverseList(startListPointer); printf("\n"); insertEntry(startListPointer, n2Pointer); printf("Traversal after insertion of n2:\n"); traverseList(startListPointer); return 0; }
int main() { input=fopen("input.dat", "r"); output=fopen("output.dat", "w"); NODET *root=createBinTree(); NODEL *firstFromList=getListFromTree(root); traverseList(firstFromList); root=getTreeFromList(&firstFromList); prettyPrint(root,0); return 0; }
int main() { FILE *f=fopen("input.txt","r"); NodeT *root=CreateBinTree(f); NodeL*firstFromList=getListfromTree(root); traverseList(firstFromList); root=getTreeFromList(firstFromList); prettyPrint(root,0); fclose(f); return 0; }
int main(){ int data[] = {1,2,3,4,5,6,7}; pNode firstNode = initList(data,7); pNode* head = &firstNode; pNode x = firstNode->m_pNext->m_pNext; DeleteNode(head,x); traverseList(head); return 0; }
int main(void) { t_btree *root, *rootFromList; f = fopen("input.dat", "r"); g = fopen("output.dat", "w"); root = createBinTree(); getListFromTree(root); traverseList(head); rootFromList = getTreeFromList(); prettyPrint(root, 0); fprintf (g, "\n"); return (0); }
int testInsertDelete() { FILE *fin = fopen("/Users/sunpeifeng/Desktop/SourceTree/DataStructures@YWM/DataStructures@YWM/SqListSource", "r"); SqList sqlist = setupLinearListUsingFile(fin); int e = 9999; deleteFromList(&sqlist, 1, &e); ElemType *a = traverseList(sqlist); printf("%d",*a); // fclose(fin); rewind(fin); compareListWithGivenResultFile(sqlist, fin); return OK; }
void main() { node *head,*tail; createList(&head); insertAtBeginning(&head,4); insertAtBeginning(&head,3); insertAtBeginning(&head,2); insertAtBeginning(&head,5); insertAtBeginning(&head,6); insertAtBeginning(&head,10); insertAtEnd(&head,1); insertInBetween(&head,9,2); traverseList(head); printf("\n"); reverseTraversal(head); reverseList(&head); traverseList(head); deleteEnd(&head); traverseList(head); deleteBeginning(&head); traverseList(head); deleteAfter(&head,2); traverseList(head); deleteList(&head); traverseList(head); // tail= getTail(head); // printf("\nTail= %d",tail->info); }
int main() { Lnode *head=NULL; Lnode *listHead=NULL; int totalNum= 10; int index =0; int value=0; buildTree(&head); traverse(head); printf("\n"); listHead = buildDouble(head); traverseList(listHead); printf("\n"); return 0; }
int main(void) { TreeT *root1; ListT *firstFromList; root1 = createBinTree(); printf("The input tree is : \n"); prettyPrint(root1, 0); firstFromList = getListFromTree(root1); printf("The list from the tree is : \n"); traverseList(firstFromList); printf("\n"); root1 = getTreeFromList(&firstFromList); printf("The tree from the list is : \n"); prettyPrint(root1, 0); return 0; }
int main() { // monitor analysis center,update the gloable variable uploadList, is always running pid_t p_analysisCenterMonitor; // start up uoload function,transfer data from analysis center to products&service center pid_t p_upload; // start up download function,transfer data from data center to analysis center //pid_t download; // log file uploading or downloading action state whether success or failed pid_t p_log; // the most important thread, the other is actived by it,expect analysisCenterMonitorTread. pid_t p_timingTask; config("system.ini"); traverseList(); //initilise upload list initUploadlist(); //initilise upload list //initDownloadloadlist(); //initialise sem_upload,sem_download state. initSem(); //create five processes,but never destroy them. { //create t analysis Center Monitor process p_analysisCenterMonitor = fork(); if( p_analysisCenterMonitor == 0) { analysisCenterMonitor(); return 0; } //create the upload process p_upload = fork(); if( p_upload == 0) { upload(); return 0; } //create the download process //download = fork(); //if( download == 0) //{ // download(); // return 0; //} //create the timingTask process p_timingTask = fork(); if( p_timingTask == 0) { timingTask(); return 0; } //create the log process p_log = fork(); if( p_log == 0) { log(); return 0; } } while(1); return 0; }
// track snake movement int movement(alt_u8 key, struct Snake snake[], int dir_array [], int pressed, int player, struct SnakeInfo * info){ int old_dir = -1; if( dir_array[left_dir] ) old_dir = left_dir; else if( dir_array[right_dir] ) old_dir = right_dir; else if( dir_array[up_dir] ) old_dir = up_dir; else if( dir_array[down_dir] ) old_dir = down_dir; int xCoor = snake[0].xCoord; int yCoor = snake[0].yCoord; int pressed_dir = get_dir_from_pressed(pressed); //printf("Pressed: %d\n", pressed); switch(pressed_dir){ case 1://0x1C://'a' if( dir_array[up_dir] || dir_array[down_dir] ) moveLeft(dir_array); break; case 2://0x1D://'w' if( dir_array[left_dir] || dir_array[right_dir] ) moveUp(dir_array); break; case 0://0x23://'d' if( dir_array[up_dir] || dir_array[down_dir] ) moveRight(dir_array); break; case 3://0x1B://'s' if( dir_array[left_dir] || dir_array[right_dir]) moveDown(dir_array); break; default: break; } if(dir_array[right_dir]){ xCoor+= 1;//16; if(xCoor > RIGHT_BOUND - 2/**col_offset*/){ //printf("Collision with right boundary!\n"); return 1; } updateSnake(snake, xCoor, yCoor, right_dir, old_dir, player, info); dir_arg = right_dir; //checkFood(snake, right_dir, player, info); }else if(dir_array[left_dir]){ xCoor-=1;//16; if(xCoor < (LEFT_BOUND+1)){//16 //printf("Collision with left boundary!\n"); return 1; //collision } updateSnake(snake, xCoor, yCoor, left_dir, old_dir, player, info); dir_arg = left_dir; //checkFood(snake, left_dir, player, info); }else if(dir_array[up_dir]){ yCoor-=1;//16; if(yCoor < (TOP_BOUND + 1)){//16 //printf("Collision with top boundary!\n"); return 1; //collision } updateSnake(snake, xCoor, yCoor, up_dir, old_dir,player, info); dir_arg = up_dir; //checkFood(snake, up_dir, player, info); }else if(dir_array[down_dir]){ yCoor+=1;//16; if(yCoor > BOT_BOUND - 2/**col_offset*/){ //printf("Collision with bottom boundary!\n"); return 1; //collision } updateSnake(snake, xCoor, yCoor, down_dir, old_dir,player, info); dir_arg = down_dir; //checkFood(snake, down_dir, player, info); } /*checkFood(snake, down_dir, player, info); checkSpeed(snake, player, info); checkFreeze(snake, player, info); recalc_freeze_times(snake, player,info); checkEdwards(snake, player, info);*/ //PLAY_SOUND(1); int check_brick_col = brickCol(snake, player); int check_self_col = traverseList(snake, player); if(check_brick_col || check_self_col){ return 1; }else{ return 0; } //return traverseList(snake); //printf("x: %d y: %d\n", xCoor, yCoor); }
int main(int argc, char *argv[]) { if (argc < 3) { printf("argument less"); exit(1); } //make and open fifo from argv[1] if (access(argv[1], F_OK) == -1) { if (mkfifo(argv[1], 0666) != 0) { perror("mkfio"); exit(1); } } int fd_sever = open(argv[1], O_RDONLY); if (fd_sever < 0) { perror("open fifo"); exit(1); } printf("open sever fifo\n"); List *client_list; initList(&client_list); Queue task_queue; initQueue(&task_queue); pthread_mutex_init(&mutex, NULL); pthread_cond_init(&cond_master, NULL); pthread_cond_init(&cond_slaver, NULL); //Create thread int index; int thread_num = atoi(argv[2]); pthread_t *th = (pthread_t *)calloc(thread_num, sizeof(pthread_t)); for (index = 0; index < thread_num; index++) { pthread_create(th + index, NULL, thread_handler, (void *)&task_queue); } fd_set set, back; FD_ZERO(&back); FD_SET(fd_sever, &back); struct timeval tm; tm.tv_sec = 10; tm.tv_usec = 0; int res; char buf[N]; while (1) { set = back; res = select(N, &set, NULL, NULL, &tm); if (res <= 0) { continue; } if (FD_ISSET(fd_sever, &set)) { memset(buf, 0, N); if (read(fd_sever, buf, N) != 0) { connectClient(buf, &client_list); } else { continue; } } traverseList(&client_list, &task_queue, &set, &back); } pthread_mutex_destroy(&mutex); pthread_cond_destroy(&cond_master); pthread_cond_destroy(&cond_slaver); close(fd_sever); unlink(argv[1]); return 0; }