7/27/2019 Ds Lab Shivam
1/8
4. Implement queue using linked list.
#include
using namespace std;struct node{
int info;node *next;
};node *start=NULL;void ins_el(){
node *tmp,*tmp2;tmp=new node;
cin>>tmp->info;tmp->next=NULL;if(start==NULL){start=tmp;}else{
tmp2=start;while(tmp2->next!=NULL)
tmp2=tmp2->next;
tmp2->next=tmp;}
}void del_el(){
node *tmp;if(start==NULL)
cout
7/27/2019 Ds Lab Shivam
2/8
}else{
while(tmp!=NULL){cout
7/27/2019 Ds Lab Shivam
3/8
3. Implement queue using array.
#include
using namespace std;void ins(int [],int &,int &);int del(int [],int &,int &);void show(int [],int &,int &);
const int size=5;int main(){
int arr[size],a,re;int front=-1,rear=-1;char ch;
do{cout
7/27/2019 Ds Lab Shivam
4/8
else if(r==size-1)cout
7/27/2019 Ds Lab Shivam
5/8
6. Implement stack using linked list.
#include
using namespace std;struct node{
int info;node *next;
};node *start=NULL;void ins_el(){
node *tmp,*save;tmp=new node;
cin>>tmp->info;tmp->next=NULL;if(start==NULL)start=tmp;
else{save=start;tmp->next=save;start=tmp;
}
}void del_el(){
node *tmp;if(start==NULL)cout
7/27/2019 Ds Lab Shivam
6/8
cout
7/27/2019 Ds Lab Shivam
7/8
5. Implement stack using array.
#include
using namespace std;void push(int [],int ,int &);int pop(int [],int &);void show(int [],int);
const int size=5;int main(){
int arr[size],a,re,item;int top=-1;char ch;
do{cout
7/27/2019 Ds Lab Shivam
8/8
a[t]=item;}
}int pop(int a[],int &t){
int ret;if(t==-1)cout