0% found this document useful (0 votes)
17 views

Ads Lab

This document discusses implementing container adapters in C++. It provides examples of using stack, queue, and priority queue container adapters. The stack example pushes and pops integers and outputs the size and top element. The queue example pushes and pops strings and outputs the size and front element. The priority queue example pushes integers, outputs the size, and pops elements in priority order. The result is that the programs using C++ container adapters were successfully executed.

Uploaded by

Pavithra S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Ads Lab

This document discusses implementing container adapters in C++. It provides examples of using stack, queue, and priority queue container adapters. The stack example pushes and pops integers and outputs the size and top element. The queue example pushes and pops strings and outputs the size and front element. The priority queue example pushes integers, outputs the size, and pops elements in priority order. The result is that the programs using C++ container adapters were successfully executed.

Uploaded by

Pavithra S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

11.

C++ CONTAINERS ADAPTER


Exp.No.: 11 Date: 20/04/2023

(IT5412 ADS Laboratory)

AIM
To implement the programs on container adapters using c++ language.

I.EXAMPLE OF STACK DATA STRUCTURE

1. SOURCE CODE

#include<iostream>
#include<stack>
using namespace std;
int main()
{
cout<<"\t C++ Stack Container Adapter\n";
cout<<"-----------------------------------------------\n";
stack<int> db;
db.push(23);
db.push(20);
db.push(77);
db.push(12);
db.push(25);
db.push(24);
db.push(6);
cout<<"Total Number of Elements in stack: "<<db.size()<<"\n";
while(db.empty()!=true)
{
cout<<" "<<db.top()<<" "<<"\n";
db.pop();
}
cout<<"------------------------------------------------\n";
return 5;
}

IT5412 ADVANCED DATA STRUCTURES LABORATORY Page 76


2. OUTPUT

II.EXAMPLE OF QUEUE DATA STRUCTURE

1. SOURCE CODE

#include<iostream>
#include<queue>
using namespace std;
int main()
{
cout<<"\t C++ Queue Container Adapter\n";
cout<<"-----------------------------------------------\n";
queue<string> db;
db.push("Chennai");
db.push("Tirupathi");
db.push("Hyderabad");
db.push("Madurai");
db.push("Delhi");
cout<<"Total Number of Elements in Queue: "<<db.size()<<"\n";
while(db.empty()!=true)
{
cout<<" "<<db.front()<<" "<<"\n";
db.pop();
}
cout<<"------------------------------------------------\n";
return 5;
}

IT5412 ADVANCED DATA STRUCTURES LABORATORY Page 77


2. OUTPUT

III.EXAMPLE OF PRIORITY QUEUE

1. SOURCE CODE

#include<iostream>
#include<queue>
using namespace std;
int main()
{
cout<<"\t C++ Priority Queue Container Adapter\n";
cout<<"----------------------------------------------------------\n";
priority_queue<int> pq;
pq.push(25);
pq.push(50);
pq.push(14);
pq.push(18);
pq.push(100);
pq.push(155);
pq.push(89);
cout<<"Total Number of Elements in Priority Queue: "<<pq.size()<<"\n";
cout<<"Displaying Elements based on Top Priority\n";
cout<<"-----------------------------------------------------------\n";
int i=1;
while(pq.empty()!=true)
{
cout<<" "<<pq.top()<<" -> "<<"Order "<<i++<<"\n";
pq.pop();
}
cout<<"----------------------------------------------------------\n";
return 5;
}

IT5412 ADVANCED DATA STRUCTURES LABORATORY Page 78


2. OUTPUT

RESULT:
Thus the programs on container adapters using c++ were executed successfully.

IT5412 ADVANCED DATA STRUCTURES LABORATORY Page 79

You might also like