0% found this document useful (0 votes)
24 views4 pages

LL Advance

This C program implements a linked list menu driven program with options to create nodes, display nodes, insert nodes at the start, end or between other nodes, delete the first, last or a node between others, and reverse the linked list. It includes function definitions for each operation on the linked list and uses pointers, dynamic memory allocation and loops to traverse and modify the linked list as needed.

Uploaded by

rockpaper12000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

LL Advance

This C program implements a linked list menu driven program with options to create nodes, display nodes, insert nodes at the start, end or between other nodes, delete the first, last or a node between others, and reverse the linked list. It includes function definitions for each operation on the linked list and uses pointers, dynamic memory allocation and loops to traverse and modify the linked list as needed.

Uploaded by

rockpaper12000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<stdio.

h>
#include<conio.h>
#include<alloc.h>
#include<ctype.h>
#include<stdlib.h>

void new_node();
void create();
void display();
void iatstart();
void iatend();
void ibetween();
void delf();
void del_e();
void rev();

struct node
{
int data;
struct node *next;
};
struct node *head,*newnode,*temp,*prenode;
int cnt=1,i=2,pos=0;

void main()
{
int ans=11;
clrscr();
while(ans!=10)
{
clrscr();
printf("\n --MENU--");
printf("\n 1. Create Nodes");
printf("\n 2. Display Nodes");
printf("\n 3. Insert At Start");
printf("\n 4. Insert At End");
printf("\n 5. Insert Node Between");
printf("\n 6. Delete First Node");
printf("\n 7. Delete End Node");
printf("\n 8. Delete Node Between");
printf("\n 9. Reverse a node list");
printf("\n 10. EXIT");

printf("\n Enter Here Your Choice <1-10> : ");


flushall(); scanf("%d",&ans);

if(ans==1)
{
create();
}
else if(ans==2)
{
display();
}
else if(ans==3)
{
iatstart();
}
else if(ans==4)
{
iatend();
}
else if(ans==5)
{
ibetween();
}
else if(ans==6)
{
delf();
}
else if(ans==7)
{
del_e();
}
else if(ans==9)
{
rev();
}
}
getch();
}

void new_node()
{
newnode->next=(struct node *)malloc(sizeof(struct node));
newnode=newnode->next;
}

void create()
{
char choice='y';
clrscr();
head=(struct node *)malloc(sizeof(struct node));
if(head==NULL)
{
printf("\n ERROR"); exit(0);
}

newnode=head;
while(choice=='y')
{
printf("\n Enter Here Data : "); flushall(); scanf("%d",&newnode->data);
printf("\n Do you want to add more nodes? <y-n>: "); choice=getche();
if(choice=='y')
{
new_node();
cnt++;
}
else
{
newnode->next=NULL;
}
}
}

void display()
{
clrscr();
newnode=head;
while(newnode->next!=NULL)
{
printf("%d\n",newnode->data);
newnode=newnode->next;
}
printf("%d",newnode->data);
printf("\n\ncount is %d",cnt);
getch();
}

void iatstart()
{
clrscr();
newnode=(struct node *)malloc(sizeof(struct node));
printf("\n Enter Data Here : "); flushall(); scanf("%d",&newnode->data);
cnt++;
newnode->next=head;
head=newnode;
}

void iatend()
{
clrscr();
temp=head;
newnode=(struct node *)malloc(sizeof(struct node));
printf("\n Enter Data Of New node : ");
flushall(); scanf("%d",&newnode->data);
newnode->next=NULL;
while(temp->next!=NULL)
{
temp=temp->next;
}
cnt++;
temp->next=newnode;
}

void ibetween()
{
clrscr();
temp=head;
newnode=(struct node *)malloc(sizeof(struct node));
printf("\n Enter Data Here : "); flushall(); scanf("%d",&newnode->data);
printf("\n Enter Position Here : "); flushall(); scanf("%d",&pos);
if(pos>cnt)
{
printf("\n Envalid Position");
}
else
{
while(i<pos)
{
temp=temp->next;
i++;
}
cnt++;
newnode->next=temp->next;
temp->next=newnode;
}
}

void delf()
{
clrscr();
if(head==NULL)
{
printf("\n You have not nodes in list");
}
else
{
temp=head;
head=head->next;
free(temp);
cnt--;
}
}

void del_e()
{
clrscr();
temp=head;
while(temp->next!=NULL)
{
prenode=temp;
temp=temp->next;
}
cnt--;
prenode->next=NULL;
free(temp);
}

void rev()
{
struct node *prenode,*currentnode,*nextnode;
clrscr();
prenode=NULL;
currentnode=nextnode=head;

while(nextnode!=NULL)
{
nextnode=nextnode->next;
currentnode->next=prenode;
prenode=currentnode;
currentnode=nextnode;
}
head=prenode;
}

You might also like