DATA STRUCTURE PROGRAMS
Transcript of DATA STRUCTURE PROGRAMS
-
7/29/2019 DATA STRUCTURE PROGRAMS
1/15
1. a. Program for virtual function in C+
+
#include
class Base
{Public:
Void display()
{
cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
2/15
{
case 1: create(); break;
case 2: deletion(); break;
case 3: search(); break;
case 4: insert(); break;
case 5: display(); break;case 6: exit(0); break;
default:
coutb[i];
}}
void deletion()
{
cout>d;
for(i=0;i
-
7/29/2019 DATA STRUCTURE PROGRAMS
3/15
q=p;
while(q->link!=NULL)
q=q->link;
t=new node;
t->data=x;
t->link=NULL;q->link=t;
}
coutdata=x;
p->link=q;
coutdata==x)
{
p=q->link;
delete q;
return;
}
r=q;
while(q!=NULL)
{
if(q->data==x){
r->link=q->link;
delete q;
return;
}
r=q;
q=q->link;
}
cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
4/15
{
node *q;
q=p;
if(q==NULL)
{
coutlink;
temp->link=temp1;}
temp=temp->link;
}
cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
5/15
cin>>p;
l.insnext(v,p);
break;
default:
cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
6/15
initial();
if(avail==-1)
{
cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
7/15
int i;
i=curs[list].next;
curs[list].next=curs[i].next;
curs[i].next=avail;
avail=i;
curs[avail].data=0;if(curs[list].next==-1)
{
curs[list].next=avail;
avail=list;
list=-1;
}
}
void delend()
{
int i,prev;
i=list;while(curs[i].next!=-1)
{
prev=i;
i=curs[i].next;
}
curs[prev].next=-1;
curs[i].next=avail;
avail=i;
curs[avail].data=0;
if(curs[list].next==-1)
{
curs[list].next=avail;
avail=list;
list=-1;
}
}
void delint()
{
int pos,i,count,prev;
coutpos;//cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
8/15
if(avail==-1) cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
9/15
}
return (0);
}
6. C++ Program to Stack ADTimplementation using linked list
#include
#include
#include
class node
{
public:
class node *next;
int data;
};class stack : public node
{
node *head;
int tos;
public:
stack()
{
tos=-1;
}
void push(int x){
if (tos < 0 )
{
head =new node;
head->next=NULL;
head->data=x;
tos ++;
}
else
{
node *temp,*temp1;
temp=head;
if(tos >= 4)
{
cout next;
temp1=new node;temp->next=temp1;
temp1->next=NULL;
temp1->data=x;
}
}
void display()
{node *temp;
temp=head;
if (tos < 0)
{
cout > ch;
switch(ch){
9
-
7/29/2019 DATA STRUCTURE PROGRAMS
10/15
case 1: cout ch;
s1.push(ch);
break;
case 2: s1.pop();break;
case 3: s1.display();break;
case 4: exit(0);
}
}
return (0);
}
7. C++ Program to Queue ADT
implementation using array
#include#include
#include
class queue
{
int queue1[5];
int rear,front;
public:
queue()
{
rear=-1;
front=-1;
}
void insert(int x)
{
if(rear > 4)
{
cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
11/15
int front,rare;
public:
queue()
{
front=-1;
rare=-1;}
void push(int x)
{
if (rare < 0 )
{
head =new node;
head->next=NULL;
head->data=x;
rare ++;
}else
{
node *temp,*temp1;
temp=head;
if(rare >= 4)
{
cout next;
temp1=new node;
temp->next=temp1;
temp1->next=NULL;
temp1->data=x;
} }
void display()
{
node *temp;
temp=head;if (rare < 0)
{
cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
12/15
#include
void insert(int,int );
void delte(int);
void display(int);
int search(int);
int search1(int,int);int tree[40],t=1,s,x,i;
main()
{
clrscr();
int ch,y;
for(i=1;i> ch;
switch(ch)
{
case 1:
cout ch;
insert(1,ch);
break;
case 2:
cout x;
y=search(1);
if(y!=-1) delte(y);
else cout
-
7/29/2019 DATA STRUCTURE PROGRAMS
13/15
search(2*s);
else if(tree[s]
-
7/29/2019 DATA STRUCTURE PROGRAMS
14/15
if(minheap[k]
-
7/29/2019 DATA STRUCTURE PROGRAMS
15/15
cin>>obj.a[i];
obj.quick(obj.a,0,obj.n-1);
cout