0% found this document useful (0 votes)
21 views8 pages

LIst

Uploaded by

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

LIst

Uploaded by

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

#include<stdio.

h>

#include<conio.h>

#include<stdlib.h>

struct node

int data;

struct node *next;

}*head,*start,*temp;

void addroot();

void addhead();

void addmid();

void display();

void del();

void main()

int choice;

clrscr();

do
{

printf("\n Enter 0 to stop");

printf("\n Enter 1 to add data atroot");

printf("\n Enter 2 to add data athead");

printf("\n Enter 3 to add data atmiddle");

printf("\n Enter 4 to delete thedata");

printf("\n Enter 5 to display \n");

scanf("%d",&choice);

switch(choice)

case 0: break;

case 1: addroot(); break;

case 2: addhead(); break;

case 3: addmid(); break;

case 4: del(); break;

case 5: display(); break;

default: printf("Incorrectvalue");

}
}while(choice!=0);

// getch();

void addroot()

temp=(struct node *)malloc(sizeof(struct node));

printf("Enter the data for new node......");

scanf("%d",&temp->data);

temp->next=NULL;

if(start==NULL)

start=temp;

head=temp;

printf("First data %d is added in theList.\n",temp->data);

return;

temp->next=start;

start=temp;
printf("%d is added in the List atRoot.\n",temp->data);

void addhead()

temp=(struct node *)malloc(sizeof(struct node));

printf("Enter the data for new node......");

scanf("%d",&temp->data);

temp->next=NULL;

if(start==NULL)

start=temp;

head=temp;

printf("First data %d is added in theList.\n",temp->data);

return;

head->next=temp;

head=temp;

printf("%d is added in the List at Head.\n",temp->data);


}

void addmid()

int i,pos;

struct node *curr=start;

temp=(struct node *)malloc(sizeof(struct node));

printf("Enter the data for new node......");

scanf("%d",&temp->data);

printf("Enter the position of data to be store......");

scanf("%d",&pos);

temp->next=NULL;

for(i=1;i<pos-1;i++)

curr=curr->next;

temp->next=curr->next;

curr->next=temp;

printf("%d is added in the List at said position.\n",temp->data);

void del()
{

int i,pos;

struct node *curr=start;

if(start==NULL)

printf("No data to delet, List is Empty \n");

return;

printf("Enter the pos of the node to delete......");

scanf("%d",&pos);

temp=start;

if(pos==1)

start=start->next;

printf("deleted data at pos 1 is %d \n",temp->data);

free(temp);

return;

}
curr=start;

for(i=1;i<pos-1;i++)

curr=curr->next;

temp=curr->next;

if(temp->next==NULL)

head=curr;

head->next=NULL;

printf("deleted data at last pos is %d \n",temp->data);

free(temp);

return;

curr->next=temp->next;

printf("deleted data at pos %d is %d \n",pos,temp->data);

free(temp);

void display()

{
if(start==NULL)

printf("No node to display, List is Empty \n");

return;

printf("\n Data in the list are\n");

temp=start;

while(temp!=NULL)

printf("%d ",temp->data);

temp=temp->next;

printf("\n");

You might also like