Add DS/C/Lab/Week7/linkedlist.c
This commit is contained in:
parent
3be00883be
commit
2c6265dd30
64
DS/C/Lab/Week7/linkedlist.c
Normal file
64
DS/C/Lab/Week7/linkedlist.c
Normal file
@ -0,0 +1,64 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user