Jan

23

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

struct node

{

int num;

struct node *next;

}*start=NULL;

typedef struct node NODE;

NODE *temp,*p;

void insert();

void display();

void insertend();

void delnode();

void main()

{

int cho,data;

clrscr();

do

{

printf(“\n 1.insert”);

printf(“\n 2.display”);

printf(“\n 3.insertend”);

printf(“\n4.delnode”);

printf(“\n5.exit”);

printf(“\nenter your choice”);

scanf(“%d”,&cho);

switch(cho)

{

case 1:insert();

break;

case 2:display();

break;

case 3:insertend();

break;

case 4:delnode();

break;

case 5:exit(0);

}

}

while(cho!=5);

getch();

}

void insert()

{

temp=(NODE*)malloc(sizeof(NODE));

printf(“enter a no”);

scanf(“%d”,&temp->num);

if(start==NULL)

{

temp->next=NULL;

start=temp;

p=temp;

}

else

{

temp->next=NULL;

p->next=temp;

p=temp;

}

}

void display()

{

NODE *temp;

for(temp=start;temp!=NULL;temp=temp->next)

printf(“\nno=%d,address=%d”,temp->num,temp->next);

}

void insertend()

{

int i,n;

printf(“Enter no that after node is inserted”);

scanf(“%d”,&n);

p=(NODE*)malloc(sizeof(NODE));

printf(“Enter element “);

scanf(“%d”,&p->num);

temp=start;

for(i=1;i<n;i++)

{

temp=temp->next;

}

if(n==0)

{

p->next=temp;

start=p;

}

else

{

p->next=temp->next;

temp->next=p;

}

}

void delnode()

{

NODE *p;

int data;

printf(“Enter element to be delete”);

scanf(“%d”,&data);

temp=start;

p=start;

while(temp!=NULL)

{

if(temp->num==data)

{

if(temp==start)

{

start=temp->next;

}

else

{

p->next=temp->next;

}

free(temp);

break;

}

p=temp;

temp=temp->next;

}

}


Leave a Reply