int main() { NODE *head,*temp; head=(NODE *)malloc(sizeof(NODE)); temp=(NODE *)malloc(sizeof(NODE)); head=NULL; START: printf("ENTER YOUR CHOICE\n"); printf("1->INSERT AT BEGNIBG\n"); printf("2->DELETE AT BEGNING\n"); printf("3->EXIT\n"); int choice,val; scanf("%d",&choice); switch(choice) { case 1: scanf("%d",&val); insert_beg(&head,val); break; case 2: temp=del_beg(&head); if(temp==NULL) printf("EMPTY LIST\n"); else printf("%d\n",temp->data); break; case 3: exit(1); default: printf("INVALID CHOICE PLEASE TRY AGAIN\n"); } goto START; return 0; }
void main() { int opt; clrscr(); do { clrscr(); printf("\npress 1 for insert beg:"); printf("\npress 2 for insert end;"); printf("\npress 3 for delete:"); printf("\npress 5 for display"); printf("\npress 99 for exit:"); printf("\nenter the option:"); scanf("%d",&opt); switch(opt) { case 1:insert_beg(); case 10:display(&ptr);break; } getch(); }while(opt!=99); getch(); }
int main() { struct clinkedlist* last; last = NULL; int choice; int value; int p, s, l, d; while(1) { printf("Choices:\n"); printf("1. Insert at beginning\n"); printf("2. Print all the nodes\n"); printf("3. Print Smallest\n"); printf("4. Print largest\n"); printf("5. Print largest - smallest\n"); printf("6. Exit\n"); printf("Enter your choice:\n"); scanf("%d", &choice); switch(choice) { case 1: printf("Enter value to be inserted:\n"); scanf("%d", &value); last = insert_beg(last,value); break ; case 2: print_all(last); break ; case 3: s = smallest(last); if (s != 0) { printf("%d\n", s); break; } printf("List is Empty!!\n"); break; case 4: l = largest(last); if (l != 0) { printf("%d\n", l); break; } printf("List is Empty!!\n"); break; case 5: d = difference(last); if (d != 0) { printf("%d\n", d); break; } printf("List is Empty!!\n"); break; case 6: exit(1); default: printf("Invalid Choice!\n"); } } return 0; }
//Main function int main() { int choice,n; while(1) { printf("\n1. Insert at beginning\n2. Insert at End\n3. Delete from beginning\n4. Delete from End\n5. Display total\n6. Count elements\n7. Exit"); printf("\nEnter your choice "); scanf("%d",&choice); switch(choice) { case 1 : printf("Enter data : "); scanf("%d", &n); insert_beg(n); break; case 2 : printf("Enter data : "); scanf("%d", &n); insert_end(n); break; case 3: del_beg(); break; case 4: del_end(); break; case 5 : display(); break; case 6: link_count(); break; case 7: exit(1); default : printf("Wrong entry please enter correct choice !!! "); break; } } }
int push(int data) { int ret=insert_beg(data,&head); if(ret == -1) { printf("Failure. \n"); return -1; } }
void main() { int opt; clrscr(); do { clrscr(); printf("\npress 1 for insert beg:"); printf("\npress 2 for insert end:"); printf("\npress 3 for insert after:"); printf("\npress 4 for insert before:"); printf("\npress 5 for delete beg:"); printf("\npress 6 for delete end:"); printf("\nlpress 7 for delete after :"); printf("\npress 8 for delete before:"); printf("\npress 9 for deleter that:"); printf("\npress 10 for delete odd:"); printf("\npress 11 for delete even:"); printf("\npress 12 for sorting:"); printf("\npress 13 for reverse:"); printf("\npress 14 for insert in sorted order ;"); printf("\npress 15 for display"); printf("\nenter the option:"); scanf("%d",&opt); switch(opt) { case 1:insert_beg(&ptr); break; case 2:insert_end(&ptr);break; case 3:insert_after(&ptr);break; case 4:insert_before(&ptr);break; case 5:delete_beg(&ptr); break; case 6:delete_end(&ptr);break; case 7:delete_after(&ptr);break; case 8:delete_before(&ptr);break; /**/ case 9:delete_that(&ptr);break; case 10:delete_alter_odd(&ptr);break; case 11:delete_alter_even(&ptr);break; case 12:sort(&ptr);break; case 13:reverse(&ptr);break; /**/ case 14:insert_sort(&ptr);break; case 15:display(&ptr);break; } getch(); }while(opt!=99); getch(); }
int main() { int ch ; char choice; do { printf("Main menu:\n"); printf("1 Create a list\n"); printf("2 Insert in the beginning\n"); printf("3 Insert in the middle\n"); printf("4 Insert at the end\n"); printf("Enter your choice\n"); scanf("%d" , &ch); switch(ch) { case 1 : create(); break; case 2 : printf("Enter the value you want to insert : "); scanf("%d" , &a); insert_beg(); break; case 3 : printf("Enter the value you want to insert : "); scanf("%d" , &a); printf("Eter the value after which you want to insert : "); scanf("%d" , &X); insert_middle(); break; case 4 : printf("Enter the value you want to insert : "); scanf("%d" , &a); insert_end(); break; default : printf("Wrong choice\n"); break; } printf("\nDo u want to continue..??\n"); fflush(stdin); scanf("%c" , &choice); printf("\n"); }while((choice=='y')||(choice=='Y')); display(); return 0; }
void NODE :: insert_loc(int val,int loc) { if(val == -1){ //-1 is an invalid or cancel value cout << endl<<MSG_INVAL_VAL<<endl; return; } if(loc<1 || loc>(No_of_nodes+1)){ //If location is out of range cout << endl<<MSG_INVAL_LOC<<endl; return; } //Create a newnode to be inserted in the list NODE *newnode; newnode = new NODE; newnode->data = val; //Set data //Set the pointers if(First == NULL){ //First ever node of the list First = newnode; Last = First; cout << "\nNew list created.\n"; } else{ //Search for correct location and insert the new node NODE *ptr, *preptr=NULL; int i=1; for(ptr=First ; ptr!=NULL ; ptr=ptr->next,++i) { if(i==loc) break; preptr = ptr; } if(ptr == First) insert_beg(val); else if(ptr == NULL) insert_end(val); else{ preptr->next = newnode; newnode->next = ptr; No_of_nodes++; cout << "\nInsertion successful.\n"; } } }
void main ( ) { clrscr(); void create ( ); void ftraverse ( ); void insert_beg ( ); void insert_end ( ); void insert_given_node ( ); create ( ); ftraverse ( ); insert_beg ( ); printf(" \n Doubly linklist after insertion at beginning: \n"); ftraverse ( ); insert_end ( ); printf(" \n Doubly linklist after insertion at end: \n"); ftraverse ( ); insert_given_node ( ); printf(" \n Doubly linklist after insertion at given node: \n"); ftraverse ( ); getch ( ); }
int main(void) { node * head; head = NULL; printf("1.insert_beg\n2.print\n3.create_loop_k\n4.check_loop\n5.end\n"); int num; int k; int test; int end; end = 1; while(end) { scanf("%d", &test); switch(test) { case 1: scanf("%d", &num); head = insert_beg(head, num); break; case 2: print(head); break; case 3: scanf("%d", &k); create_loop(head, k); break; case 4: num = check_loop(head); if (num == 1) { printf("LOOP FOUND\n"); } else { printf("LOOP NOT FOUND\n"); } case 5: end = 0; } } return 0; }
//Main Execution void main() { int a,i; clrscr(); while(1) { printf("\n1.insert_beg\n"); printf("2.insert_end\n"); printf("3.display\n"); printf("4.del_beg\n"); printf("5.del_end\n"); printf("6.del_after\n"); printf("7.insert_befroe\n"); printf("8.exit\n"); printf("\n"); printf("enter a choice:"); scanf("%d",&a); switch(a) { case 1:insert_beg(); break; case 2:insert_end(); break; case 3:display(); break; case 4:del_beg(); break; case 5:del_end(); break; case 6:del_after(); break; case 7:insert_before(); break; case 8: exit(1); default: printf("enter a valid choice"); } } }
void main ( ) { void create ( ), traverse ( ), insert_beg ( ), insert_end ( ), delete_beg ( ), delete_end ( ); clrscr ( ); create ( ); printf ("\n Circular linklist is :\n"); traverse ( ); insert_beg ( ); printf ("\n Circular linklist after inserting in beginning is :\n"); traverse ( ); insert_end ( ); printf ("\n Circular linklist after inserting at end is :\n"); traverse ( ); delete_beg ( ); printf ("\n Circular linklist after deleting from beginning is :\n"); traverse ( ); delete_end ( ); printf ("\n Circular linklist after deleting from end is :\n"); traverse ( ); getch ( ); }
int main(void) { node * head; head = NULL; printf("1.insert at begginng\n2.insert at end\n3.insert after kth node\n4.insert before kth node\n5.print\n6.delete_beg\n7.delete_end\n8.delete after kth\n9.delete before kth \n10.count_using_loop\n11.count_using_recusion\n12.end\n"); int test; int end = 1; int num; int k; while(end) { scanf("%d", &test); switch(test) { case 1: scanf("%d", &num); head = insert_beg(head, num); break; case 2: scanf("%d", &num); head = insert_end(head, num); break; case 3: scanf("%d", &k); scanf("%d", &num); head = insert_aft_k(head, k, num); break; case 4: scanf("%d", &k); scanf("%d", &num); head = insert_bef_k(head, k, num); break; case 5: print(head); break; case 6: head = delete_beg(head); break; case 7: head = delete_end(head); break; case 8: scanf("%d", &k); head = delete_aft_k(head, k); break; case 9: scanf("%d", &k); head = delete_bef_k(head, k); break; case 10: num = count_loop(head); printf("%d\n", num); break; case 11: num = count_recur(head); printf("%d\n", num); break; case 12: end = 0; break; } } return 0; }
int main() { int choice,data,pos; header=NULL; while(1) { system("cls"); printf("\nSelect your choice: "); printf("\n1. Create List "); printf("\n2. Insert Node "); printf("\n3. Display List "); printf("\n4. Delete Node "); printf("\n5. Arrange in Ascending order"); printf("\n6. Exit\n"); scanf("%d",&choice); switch(choice) { case 1: create(); break; case 2: system("cls"); printf("\nSelect your choice: "); printf("\n1. Insert at the End "); printf("\n2. Insert at the Beginning "); printf("\n3. Insert at a Specified Position "); printf("\n4. Back to main menu\n"); scanf("%d",&choice); switch(choice) { case 1: system("cls"); printf("\nEnter the data of the node: "); scanf("%d",&data); insert_end(data); printf("\nNode inserted at the end of the list"); break; case 2: system("cls"); printf("\nEnter the data of the node: "); scanf("%d",&data); insert_beg(data); printf("\nNode inserted at the beginning of the list"); break; case 3: system("cls"); printf("\nEnter the position at which you want to insert the node: "); scanf("%d",&pos); printf("\nEnter the data of the node: "); scanf("%d",&data); insert_pos(data,pos); break; case 4: break; default: printf("Invalid choice!!"); } break; case 3: display(); break; case 4: system("cls"); printf("\nSelect your choice: "); printf("\n1. Delete from the End "); printf("\n2. Delete from the Beginning "); printf("\n3. Delete from a Specified Position "); printf("\n4. Delete by the data of the node"); printf("\n5. Back to main menu\n"); scanf("%d",&choice); switch(choice) { case 1: system("cls"); delete_end(); printf("\nNode deleted from the end of the list"); break; case 2: system("cls"); delete_beg(); printf("\nNode deleted from the beginning of the list"); break; case 3: system("cls"); printf("\nEnter the position at which you want to delete the node: "); scanf("%d",&pos); delete_pos(pos); break; case 4: system("cls"); printf("\nEnter the data which you want to delete: "); scanf("%d",&data); delete_val(data); break; case 5: break; default: printf("Invalid choice!!"); } break; case 5: ascend(); system("cls"); printf("\nList rearranged in ascending order"); getch(); break; case 6: exit(0); break; default: printf("Invalid choice!!"); getch(); } } return 0; }