Академический Документы
Профессиональный Документы
Культура Документы
Algorithm:
PROGRAM
#include<stdio.h>
#include<conio.h>
struct cursor
{
char data;
int next;
}c[10];
int fp=0;
void create()
{
char a;
int p,i;
for(i=0;i<10;i++)
{
c[i].data=' ';
c[i].next=-1;
}
printf("Enter the first element to be inserted");
scanf("%c",&a);
printf("Enter the position");
scanf("%d",&p);
fp=p;
c[p].data=a;
c[p].next=0;
}
void insert(char a,int pos)
{
int i;
if(c[pos].next==-1)
{
c[pos].data=a;
for(i=0;i<10;i++)
{
if(c[i].next==0)
{
c[i].next=pos;
}
}
c[pos].next=0;
}
else
printf("\n Already data is available");
}
void display()
{
int i;
i=fp;
do
{
printf("%d\t",i);
printf("%c\t",c[i].data);
printf("%d\n",c[i].next);
i=c[i].next;
}
while(i>0);
}
void del()
{
int temp,i;
char d;
printf("\n Enter the character to be deleted");
d=getch();
if(c[fp].data==d)
{
c[fp].data=' ';
temp=c[fp].next;
c[fp].next=-1;
fp=temp;
}
else
{
i=fp;
do
{
if(c[c[i].next].data==d)
{
temp=c[i].next;
c[i].next=c[c[i].next].next;
c[temp].next=-1;
}
i=c[i].next;
}
while(i>0);
}
}
void main()
{
int opt,p;
char a;
clrscr();
create();
do
{
printf("\n 1.Insert");
printf("\n 2.Delete");
printf("\n 3.Display");
printf("\n 4.Exit");
printf("\n Enter your choice");
scanf("%d",&opt);
switch(opt)
{
case 1:
printf("\nEnter the element to be inserted");
a=getch();
printf("\nEnter the position");
scanf("%d",&p);
insert(a,p);
break;
case 2:
del();
break;
case 3:
display();
break;
}
}
while(opt<4);
}