Professional Documents
Culture Documents
Link List
Link List
Link List
#include <stdio.h>
struct node
{
int data;
struct node *add;
};
struct node *start=NULL,*temp=NULL,*New=NULL,*prev=NULL,*next=NULL;
void create();
void insert();
void Delete();
void display();
int main()
{
int ch;
do
{
printf("\n----------------Link List----------------\n");
printf("Press 1 to Create a Link List\n");
printf("Press 2 to Insert the element into Link List\n");
printf("Press 3 to Delete the element from Link List\n");
printf("Press 4 to Display all elements from Link List\n");
printf("Press 5 for EXIT\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:create();break;
case 2:insert();break;
case 3:Delete(); break;
case 4:display();break;
case 5:break;
default:printf("Invalid Choice, re-enter the choice again: ");
}
}
while(ch!=5);
return 0;
}
void create()
{
int n;
char ch;
printf("\nEnter a Value: ");
scanf("%d",&n); // temp =
1111
start = (struct node *)malloc(sizeof(struct node)); // start =
2011
start->data = n; // n = 40
start->add = NULL;
temp = start;
printf("To add more elemtns, Press 'Y': ");
scanf(" %c",&ch);
while(ch=='y' || ch == 'Y')
{
printf("\nEnter next Value: ");
scanf("%d",&n);
New = (struct node *)malloc(sizeof(struct node)); // New =
1111
New->data = n;
New->add = NULL;
temp->add = New;
temp = New;
printf("To add more elemtns, Press 'Y': ");
scanf(" %c",&ch);
}
}
void insert()
{
int n,position,count=0,i=1;
if(start == NULL)
{
printf("List Not Created, Create a list first");
}
else
{
printf("Enter a Value: ");
scanf("%d",&n);
if(position == 1)
{
New->add=start;
start = New;
}
else
{
temp = start;
if(start == NULL)
{
printf("List Not Created, Create a list first");
}
else
{
printf("Enter a Posiotion for Deletion: ");
scanf("%d",&position);
if(position == 1)
{ // temp
= 2011
temp = start; //
start = 1011
start = start->add;
printf("Deleted Element = %d: \n",temp->data);
free(temp);
}
else
{
temp = start;
}
void display()
{
if(start == NULL)
{
printf("List Not Created, Create a list first");
}
else
{
temp = start; // start = 2011