diff --git a/DS/C/Lab/Week7/linkedlist.c b/DS/C/Lab/Week7/linkedlist.c new file mode 100644 index 0000000..6dc0c3b --- /dev/null +++ b/DS/C/Lab/Week7/linkedlist.c @@ -0,0 +1,64 @@ +#include + +typedef struct Node +{ + int data; + struct Node *next; +} Node; + + + +int main() +{ + Node *head = NULL; + int choice, data; + while (1) + { + printf("Choose the Linked List Operation you would like to perform:\n"); + printf("1. Insert element BEFORE another element\n2. Insert element AFTER another element\n3. Delete a given element from the list\n4. Traverse the list\n5. Reverse the list\n6. Sort the list\n7. Delete every alternate node in the list\n7. Insert an element in a sorted list\n"); + scanf("%d", &choice); + + switch (choice) + { + case 1: + printf("Enter the value for the latest element: "); + scanf("%d", &data); + printf("Enter the number BEFORE which you would like to insert it: "); + scanf("%d", &data1); + insBef(data, data1); + break; + case 2: + printf("Enter the value for the latest element: "); + scanf("%d", &data); + printf("Enter the number AFTER which you would like to insert it: "); + scanf("%d", &data1); + insAft(data, data1); + break; + case 3: + printf("Enter the element you want to delete: "); + scanf("%d", &data); + delEle(data); + break; + case 4: + printf("List traversal"); + dispList(); + break; + case 5: + printf("The reversed link list is: "); + revList(); + break; + case 6: + printf("The sorted list is: "); + sortList(); + break; + case 7: + printf("The list after deleting every alternate node is:"); + break; + case 8: + printf("Enter the element you want to insert: "); + scanf("%d", &data); + enterSortList(); + break; + } + } +}