int main(void) { struct Node* node05 = (struct Node *)malloc(sizeof(struct Node)); node05->value = 7; node05->next = NULL; struct Node* node04 = (struct Node *)malloc(sizeof(struct Node)); node04->value = 3; node04->next = node05; struct Node* node03 = (struct Node *)malloc(sizeof(struct Node)); node03->value = 3; node03->next = node04; struct Node* node02 = (struct Node *)malloc(sizeof(struct Node)); node02->value = 2; node02->next = node03; struct Node* node01 = (struct Node *)malloc(sizeof(struct Node)); node01->value = 0; node01->next = node02; //struct Node* head = node01; printf("original: "); PrintLinkedList(node01); struct Node *copiedLL = CopyLinkedList(node01); printf("copied: "); // PrintLinkedList(CopyLinkedList(node01)); PrintLinkedList(copiedLL); return 0; }
int main () { while (true) { CellT * list1 = NULL; CellT * list2 = NULL; Vector<int> vector1 = GetVector("Give me a 1st list of numbers (-1 to quit)"); list1 = ConvertToListR(vector1); PrintLinkedList(list1); cout << SumList(list1) << endl; Vector<int> vector2 = GetVector("Give me a 2nd list of numbers (-1 to quit)"); list2 = ConvertToListR(vector2); PrintLinkedList(list2); cout << SumList(list2) << endl; cout << "Appending the list now..." << endl; //AppendList(list1, list2); Append(list1, list2); PrintLinkedList(list1); cout << SumList(list1) << endl; vector1.clear(); vector2.clear(); Deallocate(list1); //Deallocate(list2); cout << "******************** OK WE ARE DONE **********************" << endl; } return 0; }
int main(void) { struct Node* head = NULL; push(&head,6); push(&head,5); push(&head,4); push(&head,3); push(&head,2); push(&head,1); PrintLinkedList(head); swap(&head); PrintLinkedList(head); return 0; }
int main(void) { struct Node* node5 = (struct Node*)malloc(sizeof(struct Node)); node5->Data = 12; node5->Next = NULL; struct Node* node4 = (struct Node*)malloc(sizeof(struct Node)); node4->Data = 10; node4->Next = node5; struct Node* node3 = (struct Node*)malloc(sizeof(struct Node)); node3->Data = 8; node3->Next = node4; struct Node* node2 = (struct Node*)malloc(sizeof(struct Node)); node2->Data = 4; node2->Next = node3; struct Node* node1 = (struct Node*)malloc(sizeof(struct Node)); node5->Data = 2; node5->Next = node2; struct Node* head1 = node1; struct Node* node15 = (struct Node*)malloc(sizeof(struct Node)); node5->Data = 35; node5->Next = NULL; struct Node* node14 = (struct Node*)malloc(sizeof(struct Node)); node4->Data = 32; node4->Next = node15; struct Node* node13 = (struct Node*)malloc(sizeof(struct Node)); node3->Data = 25; node3->Next = node14; struct Node* node12 = (struct Node*)malloc(sizeof(struct Node)); node2->Data = 8; node2->Next = node13; struct Node* node11 = (struct Node*)malloc(sizeof(struct Node)); node5->Data = 3; node5->Next = node12; struct Node* head2 = node11; struct Node* merge; PrintLinkedList(head1); PrintLinkedList(head2); merge = merge_two_heads(head1, head2); PrintLinkedList(merge); return 0; }
int main(){ CreateLinkedList(5); CreateLinkedList(4); CreateLinkedList(3); CreateLinkedList(2); CreateLinkedList(1); CreateLinkedList(6); CreateLinkedList(7); CreateLinkedList(8); CreateLinkedList(9); CreateLinkedList(10); CreateLinkedList(11); PrintLinkedList(); //printf("Length Of Linked List %d",LengthLinkedList()); //node *trailingPtr = ReverseLinkedList(head); //trailingPtr->next = null; //PrintLinkedList(); //SortLinkedListBubbleSort(); //PrintLinkedList(); printf("\n"); //PrintLinkedListInReverse(head); MiddleElementLinkedList(); return 1; }
int main() { struct node* node05 = (struct node *)malloc(sizeof(struct node)); node05->data = 7; node05->next = NULL; struct node* node04 = (struct node *)malloc(sizeof(struct node)); node04->data = 3; node04->next = node05; struct node* node03 = (struct node *)malloc(sizeof(struct node)); node03->data = 3; node03->next = node04; struct node* node02 = (struct node *)malloc(sizeof(struct node)); node02->data = 2; node02->next = node03; struct node* node01 = (struct node *)malloc(sizeof(struct node)); node01->data = 5; node01->next = node02; struct node *head = node01; struct node *newList = NULL; CopyList(node05, newList); PrintLinkedList(newList); return 0; }
void PrintLinkedList(CellT * list) { if (list == NULL) { return; } cout << list->value << endl; PrintLinkedList(list->next); }
int main(void) { Node *head = NULL; Node *tail = NULL; TreeToLinkedList(&link0, &head, &tail); PrintLinkedList(head); return EXIT_SUCCESS; }
int main( void ) { FILE *FilePointer = OpenFile(FilePointer, 'w'); // Open file for writing Node* Head = malloc(sizeof(Node)); BootStrapFile(FilePointer); // Create our base file fclose(FilePointer); // Close the file FilePointer = OpenFile(FilePointer, 'r'); // Reopen the file for reading ReadFile(FilePointer, Head); // Read file into linked lists PrintLinkedList( Head ); // Print the linked list fclose(FilePointer); FreeLinkedList(&Head); Head = (Node* )realloc(Head, sizeof(Node)); FilePointer = OpenFile(FilePointer, 'r'); ReadFile( FilePointer, Head ); ManualEntry( Head ); fclose(FilePointer); FilePointer = OpenFile(FilePointer, 'w'); // Reopen the file for reading WriteToFile( FilePointer, Head ); fclose( FilePointer ); FreeLinkedList( &Head ); Head = (Node* )realloc(Head, sizeof(Node)); FilePointer = OpenFile(FilePointer, 'r'); ReadFile( FilePointer, Head ); UpdateRecord( Head ); // Update record PrintLinkedList( Head ); DeleteRecord( Head ); PrintLinkedList( Head ); }
int main() { // linked list code MyLinkedListElement* head = ::BuildLinkedList(c_listSize); ::printf("---Initial list.\n"); PrintLinkedList(head); int value = ::GetRandomElementValue(head); ::printf("---Selected value: %d.\n", value); MyLinkedListElement* newHead = ::RemoveLinkedListElement(head, value); ::printf("---List after removal.\n"); ::PrintLinkedList(newHead); value = ::GetRandomElementValue(head); ::printf("---Selected value: %d.\n", value); newHead = ::PartitionLinkedList(head, value); ::printf("---List after partitioning.\n"); ::PrintLinkedList(newHead); // binary tree code ::printf("---Initialize tree.\n"); MyBinaryTreeNode* treeNode = ::BuildBinaryTree(7); ::printf("---In order traversal.\n"); ::InOrderTraversal(treeNode); ::printf("---Pre order traversal.\n"); ::PreOrderTraversal(treeNode); ::printf("---Post order traversal.\n"); ::PostOrderTraversal(treeNode); ::printf("---Checking balance.\n"); bool isBalanced = ::IsTreeBalanced(treeNode, 1); // Apple stock question int stockArray [] = { 1, 2, 4, 5, 0, 2, 1, 10, 0, 1 }; int maxReturn = ::AppleStockCalculator( stockArray, 10 ); return 0; }
int main(void) { struct Node* node7 = (Node *)malloc(sizeof(struct Node)); node7->value = 15; node7->next = NULL; struct Node* node6 = (Node *)malloc(sizeof(struct Node)); node7->prev = node6; node6->value = 13; node6->next = node7; struct Node* node5 = (Node *)malloc(sizeof(struct Node)); node6->prev = node5; node5->value = 12; node5->next = node6; struct Node* node4 = (Node *)malloc(sizeof(struct Node)); node5->prev = node4; node4->value = 8; node4->next = node5; struct Node* node3 = (Node *)malloc(sizeof(struct Node)); node4->prev = node3; node3->value = 4; node3->next = node4; struct Node* node2 = (Node *)malloc(sizeof(struct Node)); node3->prev = node2; node2->value = 3; node2->next = node3; struct Node* node1 = (Node *)malloc(sizeof(struct Node)); node2->prev = node1; node1->value = 3; node1->next = node2; node1->prev = NULL; struct Node* node05 = (Node *)malloc(sizeof(struct Node)); node05->value = 7; node05->next = NULL; struct Node* node04 = (Node *)malloc(sizeof(struct Node)); node04->value = 3; node04->next = node05; struct Node* node03 = (Node *)malloc(sizeof(struct Node)); node03->value = 3; node03->next = node04; struct Node* node02 = (Node *)malloc(sizeof(struct Node)); node02->value = 2; node02->next = node03; struct Node* node01 = (Node *)malloc(sizeof(struct Node)); node01->value = 0; node01->next = node02; struct Node* head1 = node1; struct Node* tail1 = node7; struct Node* head01 = node01; PrintLinkedList(head1); // printf("\nReturn Nth node from End: "); // printf("%d\n\n", (ReturnNthNodeFromEnd(node1, 3))->value); // printf("Reverse Single Linked List: "); // LinkedListReverse(&head1); // PrintLinkedList(head1); // printf("\n"); // LinkedListReverse(&head1); // PrintLinkedList(head1); printf ("ReverseDoubleLinkedList\n"); ReverseDoubleLinkedList(&head1); PrintLinkedList(head1); // printf("Merge Linked Lists\n"); // PrintLinkedList(head01); // struct Node* mergedHead = MergeLinkedLists(head1, head01); // PrintLinkedList(mergedHead); // // printf ("ReverseKAlternateNodes\n"); // PrintLinkedList(ReverseKAlternateNodes(head1, 2)); // printf ("FrontBackSplit\n"); // struct Node *front; // struct Node *back; // FrontBackSplit(head1, &front, &back); // PrintLinkedList(front); // PrintLinkedList(back); // printf("Linked Lists Reverse Recursive\n"); // PrintLinkedList(head01); // LinkedListReverseRecursive(&head01); // PrintLinkedList(head01); puts("!!!Linked Lists!!!"); /* prints !!!Hello World!!! */ return EXIT_SUCCESS; }