int main(void){ FILE *in; int i; /* Create file handle */ if((in = fopen(FILENAME, "r")) == NULL){ printf("Unable to open file '%s'\n", FILENAME); return 1; } /* Construct sum and current number lists */ list *sum = malloc(sizeof(list)); constructList(sum, LENGTH); list *currNum = malloc(sizeof(list)); constructList(currNum, LENGTH); /* Compute the large number by repetitively loading the numbers from file and adding to sum */ loadNumber(in, sum); for (i = 1; i < NUMBERS; i++) { loadNumber(in, currNum); addNumber(sum, currNum); } /* Print the first 10 digits of sum */ printNumber(sum); /* Deconstruct all constructs */ fclose(in); destructList(sum); free(sum); free(currNum); return 0; }
int main() { vector<int> data1{-10,-9,-8,-7,-2,-1,0,1}; vector<int> data2{1}; auto pl1 = constructList(data1); auto pl2 = constructList(data2); vector<ListNode*> data{nullptr, pl1, pl2, nullptr}; auto pr = Solution().mergeKLists(data); while(pr!= nullptr){ cout << pr->val << "->"; pr = pr->next; } cout << endl; return 1; }
/* This is a simple test program. Note that you should write * your own test program when you are implementing above functions. * When you think that all your functions work correctly, use this * main function. */ int main(void) { struct list *myList; int i; myList = constructList(); for(i = 0; i < 5; i++) { printf("Adding %i\n", i); add(myList, i); printList(myList); } printf("\n"); printf("Remove index 0 (first node on the link chain)\n"); i = removeEntry(myList,0); printf("The function removeEntry returns %i.\n", i); printList(myList); printf("Remove index 3 (last node on the link chain)\n"); i = removeEntry(myList,3); printf("The function removeEntry returns %i.\n", i); printList(myList); printf("Remove index 1 (middle node on the link chain)\n"); i = removeEntry(myList,1); printf("The function removeEntry returns %i.\n", i); printList(myList); return 0; }
int main() { vector<int> data{1,2}; auto p = constructList(data); auto lp = Solution().swapPairs(p); while(lp) { cout << lp->val << "->"; lp = lp->next; } return 1; }
// Allocate storage, construct triangulation, compute voronoi corners int CDelaunay::triangulate(SEdgeVector **edges, int n_sites, int width, int height) { EdgePointer cep; deleteAllEdges(); buildTriangulation(n_sites); cep = consolidateEdges(); *edges = ev; // Note: construction_list will change ev return constructList(cep, width, height); }
int main() { vector<int> data{1,2}; auto root = constructList(data); ListNode** pp = &root; cout << "begin" << endl; while (*pp) { cout << (*pp)->val << ","; pp = &(*pp)->next; } cout << "--" << endl; root = Solution().reverseKGroup(root, 3); pp = &root; while (*pp) { cout << (*pp)->val << ","; pp = &(*pp)->next; } return 1; }