int main() { int a; head = NULL; push( &head, 3); push( &head, 2); push( &head, 1); push( &head, 1); checkList(); printf("Head Node: \n"); printNode(head); printf("List: \n"); printList(head); /* Count Test */ printf("Count of 1 = %d\n", Count( head, 1 )); /* GetNth test */ printf("Value at node 2 = %d \n", GetNth( head, 2)); scanf("%d",&a); }
void Ga::selectSurvive(vector<Individual*> &family) { sort(family.begin(),family.end(),Individual::Comparator); m_Population.push_back(family[0]); Util::removeVector(family,0); int r=roulette(family); m_Population.push_back(family[r]); Util::removeVector(family,r); for(int i=0; i<family.size(); i++) { delete(family[i]); } #ifdef DEBUG cout<<"crossover"<<endl; printList(); #endif }
int main() { ListHndl intList; intList = newList(); int data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; /* * Integer list testing * */ printHeading(" INTEGER LIST ", '#', 80); printList(stdout, intList); accessorTest("isEmpty", 1, isEmpty(intList)); for(int i = 0; i < 10; i++) { insertAtFront(intList, data[i]); mutatorTest("%s : data = %d", "insertAtFront", data[i]); } moveFirst(intList); for(int i = 0; i < 5; i++) { printList(stdout, intList); insertBeforeCurrent(intList, data[i]); mutatorTest("insertBeforeCurrent : data = %d", data[i]); moveNext(intList); } accessorTest("isEmpty", 0, isEmpty(intList)); printList(stdout, intList); moveFirst(intList); while( !offEnd(intList) ) { printList(stdout, intList); moveNext(intList); } moveLast(intList); while( !offEnd(intList) ) { printList(stdout, intList); movePrev(intList); } makeEmpty(intList); mutatorTest("makeEmpty( intList)"); printList(stdout, intList); accessorTest("isEmpty", 1, isEmpty(intList)); freeList(intList); return 0; }
int main(){ node* head = NULL; push(&head, 10); push(&head, 4); push(&head, 15); push(&head, 20); push(&head, 50); /* Create a loop for testing */ head->next->next->next->next->next = head->next->next; detectAndRemoveLoop(head); printf("Linked List after removing loop \n"); printList(head); return 0; }
void printGraph ( FILE* out, Graph G ) { if ( G == NULL ) { printf ( "Graph Error: printGraph() on NULL graph" ); exit(1); } int x; for( x = 1; x <= getOrder(G); x++) { fprintf(out, "%d: ", x); printList ( out, G->adjacency[x] ); fprintf(out, "\n"); } }
// insert proper tests here int main (int argc, const char * argv[]) { int start,end; printf("input start and end\n"); scanf("%d %d",&start,&end); link list = fromTo (start, end); printList (list); printf("The sum is %d.\n",sumListItems(list)); dlink doublelist = doublify(list); printDList(doublelist); freeList(list); freeDList(doublelist); return 0; }
void shellsort3(int *a, int n) { int i, j, gap; for (gap = n / 2; gap > 0; gap /= 2) { printf("gap = %d\n", gap); for (i = gap; i < n; i++) { for (j = i - gap; j >= 0 && a[j] > a[j + gap]; j -= gap) { DataSwap(&a[j - 1], &a[j]); printDataSwap('i', i, 'j', j); printList(a, n); } } } }
void printGraph(GraphRef g){ for(int i=0; i<g->numVertices; i++){ printf("Node %d:\n", i); if(i!=0){ printf("Parent "); printList(g->parent[i]); } printf("\tColor %d, Dist %d", g->color[i], g->distance[i]); printf("\tEdges:"); ListRef index = g->vertices[i]; moveFirst(index); while(!offEnd(index)){ printf("%d, ",getCurrent(index)); moveNext(index); } } }
int main(){ int i=0; char name[50]; int roll_no; node *first=NULL; for(i=0;i<5;i++){ printf("Enter Name:"); readline(name,50); printf("Enter Roll No:"); scanf("%d",&roll_no); // first=addToBegining(first,name,roll_no); first=addToEnd(first,name,roll_no); } printList(first); }
int main() { int a[N], b[N], i; for (i = 0; i< N; i++) { a[i] = i; b[i] = 0; } veccpy(a, b, N); if (memcmp(a, b, N * sizeof (int)) != 0) { printList((int *)a, (int *)b, N); printf ("Vector copy C case - Failed \n"); } else { printf ("Vector copy C case - Passed \n"); } return 0; }
int main() { struct ListNode * t1[4]; for(int i = 0; i< 4; i++){ t1[i] = malloc(sizeof(struct ListNode)); } t1[0]->val = 1; t1[1]->val = 2; t1[2]->val = 2; t1[3]->val = 5; t1[0]->next = t1[1]; t1[1]->next = t1[2]; t1[2]->next = t1[3]; t1[3]->next = NULL; struct ListNode * hhh = deleteDuplicates(t1[0]); printList(hhh); }
void Function::outputFile(string filename) { ofstream output(filename); if (output.is_open() == true) { output << "var code = {\"type\":\"function\", \"code\":\""; output << addBackslashes(statements.statement); output << "\", \"inner\":["; output << printList(statements.children); output << "]};"; output.close(); } else { //error } }
static void inputCommand(void) { char command[20]; printf("Type 'help' to see help\n\n"); while (true) { fgets(command, 20, stdin); if (command[strlen(command) - 1] == '\n') { command[strlen(command) - 1] = '\0'; } if (_stricmp(command, "about") == 0) { printAbout(); } else if (_stricmp(command, "help") == 0) { printHelp(); } else if (_stricmp(command, "log on") == 0) { g_RPCServer.SetLogOn(true); } else if (_stricmp(command, "log off") == 0) { g_RPCServer.SetLogOn(false); } else if (_stricmp(command, "list") == 0) { printList(); } else if (_stricmp(command, "quit") == 0) { if (g_MountProg.GetMountNumber() == 0) { break; } else { printConfirmQuit(); fgets(command, 20, stdin); if (command[0] == 'y' || command[0] == 'Y') { break; } } } else if (_stricmp(command, "refresh") == 0) { g_MountProg.Refresh(); } else if (_stricmp(command, "reset") == 0) { g_RPCServer.Set(PROG_NFS, NULL); } else if (strcmp(command, "") != 0) { printf("Unknown command: '%s'\n", command); printf("Type 'help' to see help\n"); } } }
void main(void) { int i = 1; int x = 0; List1Element * head = createList(); intro(); scanf ("%d", &i); while (i) { switch (i) { //case 0: // delList(head); // break; case 1 : printf("enter the value\n"); scanf("%d", &x); insertEl (head, x); break; case 2 : if (isEmpty(head)) printf("sorry it seems to be nothing here\n"); else printf("%d\n", getMin(head)); break; case 3: if (isEmpty(head)) printf("sorry it seems to be nothing here\n"); else printList(head); printf("\n"); break; default: printf("no no no, you're doing it wrong!\n"); } if (i) { intro(); scanf ("%d", &i); } } delList(head); delete head; }
int _tmain(int argc, _TCHAR* argv[]) { printf("0 - exit\n"); printf("1 - add value to sorted list\n"); printf("2 - remove value from list\n"); printf("3 - print list\n"); IntList *head = newList(-1); while(true) { printf("Input command:\n"); int command = 0; scanf("%d", &command); int val = 0; switch (command) { case 0: deleteList(head); return 0; case 1: printf("Input value:\n"); scanf("%d", &val); addToSortedList(head, val); break; case 2: printf("Input value:\n"); scanf("%d", &val); removeValue(head, val); break; case 3: printList(head); break; }; } deleteList(head); scanf("%*s"); return 0; }
string Function::printList(vector<struct node> sequence) //to JSON { string output; for (unsigned int i = 0; i < sequence.size(); ++i) { output.append("{"); if (sequence.at(i).children.size() > 0) { string type; if (sequence.at(i).statement.at(0) == 'i') type = "if"; else if (sequence.at(i).statement.at(0) == 'f') type = "for"; else if (sequence.at(i).statement.at(0) == 'w') type = "while"; else if (sequence.at(i).statement.at(0) == 'd') type = "do"; else if (sequence.at(i).statement.at(0) == 'e' && sequence.at(i).statement.size() > 6) type = "else if"; else if (sequence.at(i).statement.at(0) == 'e') type = "else"; output.append("\"type\":\""); output.append(type); output.append("\", \"code\":\""); output.append(addBackslashes(sequence.at(i).statement)); output.append("\", \"inner\":["); output.append(printList(sequence.at(i).children)); output.append("]"); } else { output.append("\"type\":\"statement\", \"code\":\""); output.append(addBackslashes(sequence.at(i).statement)); output.append("\", \"inner\":[]"); } output.append("},"); } output.erase(output.end() - 1, output.end()); return output; }
int main (int argc, const char * argv[]) { TYPE task1, task2, task3, task4, task5, task6, task7, task8, task9, task10; DynArr mainList; int i; initDynArr(&mainList, 10); /* create tasks */ task1 = createTask(9, "task 1"); task2 = createTask(3, "task 2"); task3 = createTask(2, "task 3"); task4 = createTask(4, "task 4"); task5 = createTask(5, "task 5"); task6 = createTask(7, "task 6"); task7 = createTask(8, "task 7"); task8 = createTask(6, "task 8"); task9 = createTask(1, "task 9"); task10 = createTask(0, "task 10"); /* add tasks to the dynamic array */ addDynArr(&mainList, task1); addDynArr(&mainList, task2); addDynArr(&mainList, task3); addDynArr(&mainList, task4); addDynArr(&mainList, task5); addDynArr(&mainList, task6); addDynArr(&mainList, task7); addDynArr(&mainList, task8); addDynArr(&mainList, task9); addDynArr(&mainList, task10); /* sort tasks */ sortHeap(&mainList); /* print sorted tasks from the dynamic array */ for (i = 0; i < mainList.size; i++) { printf("%d\n", mainList.data[i].priority); } printList(&mainList); return 0; }
int main() { int i,size=15; ElementList E; Element e1; e1.id=2000; e1.regstatus=0; for(i=0;i<size;i++) { E[i].id=i; E[i].regstatus=(i%3); //0= Success, 1 = Conflict, 2 = Deny } // R containing All (size number) registered student records ListHead ks, kd, kc; ks=createList(); kd=createList(); kc=createList(); for (i = 0; i < size; i++) { if (E[i].regstatus == 0) { insertAtTail (E[i], ks); } else if (E[i].regstatus == 1) { insertAtHead (E[i], kc); } else { insertAtHead (E[i], kd); } } printf("\n\nSUCCESS LIST\n"); printList(ks); printf("\n\nCONFLICT LIST\n"); printList(kc); printf("\n\nDENY LIST\n"); printList(kd); deleteFromHead(ks); deleteFromTail(kc); deleteFromHead(kd); printf("\n\nSUCCESS LIST After Deletion\n"); printList(ks); printf("\n\nCONFLICT LIST After Deletion\n"); printList(kc); printf("\n\nDENY LIST After Deletion\n"); printList(kd); }
int main(int argc, char** argv) { //Linked list header head = Malloc(sizeof(struct ListNode)); head->data = -1; //Negative one for header data (start appending at zero in threads) head->prev = NULL; head->next = NULL; //Spawn some threads to insert into the linked list pthread_t threads[NUM_THREADS]; int t, rc; for(t=0; t<NUM_THREADS; t++) { rc = pthread_create(&threads[t], NULL, doAppend, (void *)t); if (rc) { printf("ERROR: return code from pthread_create() is %d\n", rc); exit(-1); } } //Wait for threads to finish void * status; for(t=0; t<NUM_THREADS; t++) { rc = pthread_join(threads[t], &status); if (rc) { printf("ERROR: return code from pthread_join() is %d\n", rc); exit(-1); } //printf("Main: completed join with thread %d having a status of %d\n",t,status); } //Print the list after all threads are done printList(head); //Exit main properly pthread_exit(NULL); }
static int partition(void *data, int esize, int i, int k, int (*compare)(const void *key1, const void *key2)) { char *a = data; void *pval, *temp; int r[3]; if ((pval = malloc(esize)) == NULL) { return -1; } if ((temp = malloc(esize)) == NULL) { free(pval); return -1; } r[0] = (rand() % (k - i + 1) + i); r[1] = (rand() % (k - i + 1) + i); r[2] = (rand() % (k - i + 1) + i); printList(r, 3); issort(r, 3, sizeof(int), compare_int); memcpy(pval, &a[r[1] * esize], esize); i--; k++; while (1) { do { k--; } while (compare(&a[k * esize], pval) > 0); do { i++; } while (compare(&a[i * esize], pval) < 0); if (i >= k) { break; } else { memcpy(temp, &a[i *esize], esize); memcpy(&a[i * esize], &a[k * esize], esize); memcpy(&a[k * esize], temp, esize); } } free(pval); free(temp); return k; }
int main(int argc, char **argv) { printf("This is the input\n"); printf("0: %s 1: %s 2: %s\n", argv[0], argv[1], argv[2]); //initialize root list and current root = malloc(sizeof (struct tree)); root->next = NULL; current = malloc(sizeof (struct tree)); current->next = NULL; //grab characters int i; for (i = 0; *(argv[1] + i) != '\0'; i++) { insert(argv[1]); } printList(); return 0; }
int main() { //test(); system("clear"); int num, choice, c; char name[NAMELEN]; char sex; Llist L; L = createList(); while(1){ choice = option(); if(choice == 1){ system("clear"); printf("please enter job number: "); scanf("%d",&num); printf("\nplease enter name: "); while ((c=getchar()) != '\n' && c != EOF); //fflush() can't use in gcc fgets(name, NAMELEN, stdin); printf("\nplease enter sex: "); scanf("%c",&sex); insertNode(L,num,name,sex); continue; } if(choice == 2){ system("clear"); printf("please enter delete number: "); scanf("%d",&num); deleteNode(L,num); continue; } if(choice == 3){ system("clear"); printList(L); continue; } if(choice == 0){ return 0; } } return 0; }
void removeMiddleElement() { if(isInitialized!=1) { printf("\n List isn't initialized!\n Type 7 for initialize."); return; } if (listsize<=2) { printf("Too little elements. Need at least 2."); return; } printf("Type position\n"); int p; scanf("%i",&p); if (p==1) { printf("\n To delete first element type 4\n"); return; } else if(p==listsize) { { printf("\n To delete last element type 6\n"); return; } } int i=1; list* h=head; if (p>2) p--; else p=p-2; while (i++<p) { h=h->next; } list* q=h; h=h->next; q->next=h->next; free(h); listsize--; printList(); }
int StandardPrompt() { char command[20] = " "; char string[400]; char argument[400]; while (strcmp(command,"quit\n") != 0) { printf("\n"); printf("cmd: info, list-nodes, delete-node, quit\n"); printf("esp> "); fgets (string,400,stdin); strcpy(argument,string); strcpy(command,getCommand(string, command)); if(strcmp(command,"info\n")==0) { printf("-----------------------\n" "Version 0.1\n0664jester\n" "-----------------------\n"); } else if(strcmp(command,"quit\n")==0) { } else if(strcmp(command, "list-nodes\n")==0) { printList(); } else if (strcmp(command,"delete-node\n")==0) { deletenode(); } else { printf("command unknown.\n"); } } return 1; }
int main() { struct ListNode *node1 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node2 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node3 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node4 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node5 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node6 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node7 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node8 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node9 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode *node10 = (struct ListNode*)malloc(sizeof(struct ListNode)); node1->m_nValue = 1; node1->m_pNext = node3; node2->m_nValue = 2; node2->m_pNext = node4; node3->m_nValue = 3; node3->m_pNext = node5; node4->m_nValue = 4; node4->m_pNext = node6; node5->m_nValue = 5; node5->m_pNext = node7; node6->m_nValue = 6; node6->m_pNext = node8; node7->m_nValue = 7; node7->m_pNext = node9; node8->m_nValue = 8; node8->m_pNext = node10; node9->m_nValue = 9; node9->m_pNext = NULL; node10->m_nValue = 10; node10->m_pNext = NULL; struct ListNode *head = NULL; // head = merge(node1, node2); head = mergeRecursive(node1, node2); printList(head); // free operation return 0; }
int main(void){ EList list; initList(&list); setListSize(&list,200); insertListItem(&list,"f6","zero", "dir"); // printList(list); // printf("size: %d\n", list.size); //printf("\n"); insertListItem(&list,"f7","one", "dir"); insertListItem(&list,"f7","one", "dir"); insertListItem(&list,"f7","two","dir"); insertListItem(&list,"a8","two", "dir"); insertListItem(&list,"a8","three", "dir"); insertListItem(&list,"a8","four", "dir"); insertListItem(&list,"a8","five", "dir"); insertListItem(&list,"a8","six", "dir"); insertListItem(&list,"a8","seven", "dir"); insertListItem(&list,"a8","eight", "dir"); insertListItem(&list,"a8","nine", "dir"); insertListItem(&list,"a8","ten", "dir"); insertListItem(&list,"a8","eleven", "dir"); insertListItem(&list,"a8","twelve", "dir"); insertListItem(&list,"a8","thirteen", "dir"); insertListItem(&list,"a8","fourteen", "dir"); insertListItem(&list,"a8","fifteen", "dir"); insertListItem(&list,"a8","sixteen", "dir"); int x=0; for(;x<list.item_count;x++){ printSL(list,x); } printf("item_count: %d %d\n", list.item_count, list.size); printf("\n"); printList(list); return 0; }
int main() { countdown(10); countdownEven(10); printf("%s %s a palindrome\n", "MADAM", isPalindrome("MADAM", strlen("MADAM")) ? "is" : "is not"); LinkedList a = {3, NULL}; LinkedList b = {-4, &a}; LinkedList c = {2, &b}; LinkedList d = {1, &c}; printf("Sum: %d\n", sum(&d)); printf("isAllPositive: %d\n", isAllPositive(&d)); printf( isAllPositiveLessReadableButShorterWithALongerFunctionName(&d) ? "All positive!\n" : "Not all positive!\n"); printList(&d); printf("\n"); printListReverse(&d); printf("\n"); //1 -> 2 -> -4 -> 3 -> //3 -> -4 -> 2 -> 1 -> // BinTree* bt1 = NULL; // BinTree bt = NULL; // can't assign NULL to struct BinTree jean = {"Jean", 24, NULL, NULL}; BinTree jeane = {"Jeane", 27, NULL, NULL}; BinTree icel = {"Icel", 10, NULL, NULL}; BinTree candace = {"Candace", 48, &jean, &jeane}; BinTree lovely = {"Lovely", 9, &icel, NULL}; BinTree honey = {"Honey", 40, &lovely, NULL}; BinTree jj = {"JJ", 3, &honey, &candace}; printf("Population: %d\n", pop(&jj)); printf("Max sales: %d\n", maxSales(&jj)); printf("Num levels: %d\n", numLevels(&jj)); return 0; }
int scanpel(const char* eventname) /* print event list */ { char message[80]; int prio; event_list *pel; do /* multithreading: make sure pel is consistent */ pel = pevent_list[0]; while (pel != pevent_list[0]); for (; pel; pel = pel->next) { if (!eventname || strcmp(pel->event_name, eventname) == 0) { for (prio = 0; prio < NUM_CALLBACK_PRIORITIES; prio++) { if (ellCount(&pel->scan_list[prio].list) == 0) continue; sprintf(message, "Event \"%s\" Priority %s", pel->event_name, priorityName[prio]); printList(&pel->scan_list[prio], message); } } } return 0; }
void reverseList2(List head) { Node *p, *q, *r; p = q = r = head->next; while(q->next != NULL) q = q->next; // printf("%d", q->date); while(q != p) { head->next = p->next; p->next = q->next; q->next = p; p = head->next; printList(head); } }
void test_reverseBetween() { { int a[] = { 1, 2, 3, 4, 5 }; ListNode *p1 = createList(a, sizeof(a) / sizeof(a[0])); printList(p1); ListNode *p = reverseBetween(p1, 2, 4); printList(p); printf("-----------------------\n"); } { int a[] = { 1, 2, 3, 4, 5 }; ListNode *p1 = createList(a, sizeof(a) / sizeof(a[0])); printList(p1); ListNode *p = reverseBetween(p1, 3, 4); printList(p); printf("-----------------------\n"); } { int a[] = { 1, 2, 3, 4, 5 }; ListNode *p1 = createList(a, sizeof(a) / sizeof(a[0])); printList(p1); ListNode *p = reverseBetween(p1, 1, 5); printList(p); printf("-----------------------\n"); } { int a[] = { 1, 2, 3, 4, 5 }; ListNode *p1 = createList(a, sizeof(a) / sizeof(a[0])); printList(p1); ListNode *p = reverseBetween(p1, 1, 3); printList(p); printf("-----------------------\n"); } }