void insertNthTest(void) { Node *head = NULL; insertNth(&head, 0, 13); insertNth(&head, 0, 7); insertNth(&head, 1, 42); insertNth(&head, 1, 5); printList(head); }
int main(int argc, const char * argv[]) { //printList(appendNode(&(BuildWithLocalRef()), 2)); //doesn't work? &(2376ut) doesn't work not a lvalue Node* head=BuildOneTwoThree(); appendNodeWithPush(&head, 4); appendNode(&head, 4); appendNode(&head, 4); Node* test5=BuildWithLocalRef(); Push(&test5, 6); insertNth(&test5, 4, 3); //printList(test5); insertSort(&test5); append(&test5, &head); //printList(test5); Node *first=NULL,*second=NULL; //pop(&test5); //split(test5, &first, &second); //printList(first); //printList(second); //removeDuplicates(second); //printList(first); //printList(second); //moveNode(&first, &second); //printList(first); //printList(second); alternatingSplit(test5, &first, &second); //printList(first); //printList(second); //Node* test=shuffleMergeRecursive(first, second); //printList(test); Node* test1=BuildOneTwoThree(); Node* test2=BuildOneTwoThree(); pop(&test2); appendNode(&test2, 7);; appendNode(&test1, 5); //printList(test1); //printList(test2); append(&test1, &test2); //printList(test1); mergeSort(&test1); //printList(test1); Node* t4=BuildOneTwoThree(); Node* t5=BuildOneTwoThree(); appendNode(&t5, 6); appendNode(&t4, 6); appendNode(&t4, 7); appendNode(&t5, 8); Push(&t5, 0); Push(&(t5->next), 1); //printList(t5); //printList(t4); //printList(sortedIntersect(t4, t5)); recursiveReverse(&t5); printList(t5); return 0; }
void insertSort(){ struct node * temp = head, *p, *q; if(temp == NULL){ printf("List Empty\n"); return; } // Below is sortedInsert implemented int count = 0; p = (struct node *)malloc(sizeof(struct node)); p->data = temp->data; p->next = NULL; q = temp; temp = temp->next; head = p; tail = p; free(q); while(temp != NULL){ q = temp; if(temp->data < p->data){ push(temp->data); p = head; } else if(temp->data > tail->data) append(temp->data); else{ while(p->data < temp->data){ count += 1; p = p->next; } insertNth(count, temp->data); p = head; count = 0; } temp = temp->next; free(q); } }
int main(void){ Node *myList = NULL; Node *dupList = NULL; //Node *nn= newNode(4); Node *randomList =NULL; append(&myList, 10); //append(&myList, 15); printList(myList); myList= buildOneTwoThree(); if(myList != NULL){ printList(myList); printf("\nmyList length = %d; ", linkLength(myList)); } push(&myList, 0); push(&(myList->next), 42); printList(myList); append(&myList,5); printList(myList); dupList = copyList(myList); printList(dupList); changeToNull(&dupList); printList(dupList); dupList=addAtHead(); printList(dupList); dupList= buildWithSpecialCase(); printList(dupList); dupList=buildWithDummyNode(); printList(dupList); printf("\n List has %d 5.", countTest(dupList,5)); printf("\n 3rd Element of list = %d", getNth(dupList, 3)); //deleteList(&dupList); insertNthTest(); //sortedInsert(&dupList, nn); printList(dupList); // random list insertNth(&randomList, 0, 13); insertNth(&randomList, 1, 13); insertNth(&randomList, 2, 27); insertNth(&randomList, 3, 55); insertNth(&randomList, 4, 55); printList(randomList); removeDuplicates(randomList); printList(randomList); //insertSort(&randomList); //printList(randomList); //testAppendList(); //testFrontBackSplit(); return 0; }
int main(){ int c, n, r; do { printf("0. Show\n"); printf("1. Append\n"); printf("2. Push\n"); printf("3. pop\n"); printf("4. Count Nodes\n"); printf("5. Get nth element\n"); printf("6. Delete List\n"); printf("7. Insert at nth index\n"); printf("8. InsertSort the List\n"); printf("9. FrontBackSplit\n"); printf("10. Remove Duplicates\n"); printf("11. Reverse the List\n"); printf("12. Alternating Split\n"); printf("13. Make a Dummy List\n"); printf("14. Shuffle Merge\n"); printf("15. EXIT\n"); printf("Your Choice : "); scanf("%d", &c); switch(c){ case 0 : show(); break; case 1 : printf("Enter a number : "); scanf("%d", &n); append(n); break; case 2 : printf("Enter a number : "); scanf("%d", &n); push(n); break; case 3 : if((r = pop()) > 0) printf("%d\n", r); else printf("List Empty\n"); break; case 4 : printf("%d\n", countNodes()); break; case 5 : printf("Enter the index : "); scanf("%d", &n); ((r = getNth(n)) >= 0) ? printf("%d\n", r) : printf("Index out of Range\n"); break; case 6 : deleteList(); break; case 7 : printf("Enter the index and the number : "); scanf("%d%d", &r, &n); if(insertNth(r, n) < 0) printf("Index out of Range. Aborting..."); break; case 8 : insertSort(); break; case 9 : frontBackSplit(); break; case 10: removeDuplicate(); break; case 11: reverse(); break; case 12: alternatingSplit(); break; case 13: makeDummyList(); break; case 14: shuffleMerge(); break; case 15: exit(0); default: printf("wrong Choice\n"); exit(0); } }while(c >= 0 && c <= 14); }