c program for insert in order pid in order and delete specific patient information - c program with parth patthar

c program with parth patthar

learn c and c++ in better way and with simple example.

Believe on your own logic

Sunday, September 30, 2018

c program for insert in order pid in order and delete specific patient information

#include<stdio.h>
#include<conio.h>
struct node
{
int pid;
char name[20];
struct node *link;
};
struct node *nn,*prev,*first,*temp;
void insert()
{
nn=(struct node*)malloc(sizeof(struct node));
if(nn==NULL)
{
printf("\n memory not allocated");
return;
}
printf("\n enter pid:");
scanf("%d",&nn->pid);
printf("\n enter name:");
scanf("%s",nn->name);
if(first==NULL)
{
first=nn;
first->link=NULL;
return;
}
if(first->pid>nn->pid)
{
nn->link=first;
first=nn;
return;
}
temp=first;
while(temp->link!=NULL&&temp->link->pid<nn->pid)
{
temp=temp->link;
}
nn->link=temp->link;
temp->link=nn;
}
void delet()
{
int item;
if(first==NULL)
{
printf("\n list is empty:");
getch();
return;
}
printf("\n enter pid for delete:");
scanf("%d",&item);
if(first->pid==item)
{
temp=first;
first=first->link;
free(temp);
return;
}
temp=first;
prev=NULL;
while(temp->link!=NULL&&temp->pid!=item)
{
prev=temp;
temp=temp->link;
}
if(temp->pid!=item)
{
printf("\n node not found:");
getch();
return;
}
prev->link=temp->link;
free(temp);
}
void display()
{
temp=first;
while(temp!=NULL)
{
printf("\n pid=%d",temp->pid);
printf("\n name=%s",temp->name);
temp=temp->link;
}
getch();
}
void main()
{
int ch;
do
{
clrscr();
printf("\n 0)for exit");
printf("\n 1)for insert");
printf("\n 2)for display:");
printf("\n 3)for delete:");
printf("\n enter your choice:");
scanf("%d",&ch);
switch(ch)
{

case 1:insert();
break;
case 2:display();
break;
case 3:delet();
break;
}
}while(ch!=0);
}



No comments:

Post a Comment