#include<stdio.h>
#include<conio.h>
struct node
{
int info;
node *next;
}*start,*nptr,*save,*ptr,*end;
node *create(int);
int new_node_input();
void insert_node(node *,int);
void display_node(node *);
void del_node(node *,int);
void main()
{
clrscr();
int choice,inf;
start = end = NULL;
inf = new_node_input();
nptr = create(inf);
insert_node(nptr,1);
display_node(start);
do
{
printf("\n\n\t\t What Would Like To Do Now ? \n");
printf("\n 1. Inserting Node From the Beginning ");
printf("\n 2. Inserting Node From the End ");
printf("\n 3. Deleting Node From the Beginning");
printf("\n 4. Deleting Node From the End");
printf("\n\t\t ..... Hit Other Keys To Exit .....");
printf("\n\n Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1 :
case 2 : inf = new_node_input();
nptr = create(inf);
insert_node(nptr,choice);
break;
case 3 :
case 4 : del_node(nptr,choice);
break;
default : break;
}
display_node(start);
}while((choice>=1)&&(choice<=4));
printf("\n\n\t\t !!!! Thanks Fro Using The Program !!!!");
getch();
}
int new_node_input()
{
int number;
printf("\n Enter The Information For The New Node : ");
scanf("%d",&number);
return number;
}
node *create(int number)
{
ptr = new node;
ptr->info = number;
ptr->next = NULL;
return ptr;
}
void insert_node(node *np,int choice)
{
printf("\n\n\t\tInsertion has been done \n\n");
getch();
if(start == NULL)
start = end = np;
else
{
if(choice == 1)
{
save = start;
start = np;
np->next = save;
}
else
{
end->next = np;
end = np;
}
}
}
void display_node(node *np)
{
printf("\n\n Now The List Is : \n\t");
while(np != NULL)
{
printf("%d ->",np->info);
np = np->next;
}
}
void del_node(node *np,int choice)
{
printf("\n\n\t\tDeletion has been done \n\n");
getch();
if(start == NULL)
printf("\n\nUNDERFLOW !!!\n\n");
else
{
if (choice == 3)
{
np = start;
start = start->next;
}
else
{
np = end;
end = NULL;
}
delete np;
}
}
No comments:
Post a Comment