SlideShare a Scribd company logo
#include
#include
#include
using namespace std;
template //For Template
void bogosort(std::vector& array) //For bogosort
{
while (! is_sorted(array))
{
std::random_shuffle(array.begin(), array.end());
}
}
template
bool is_sorted(const std::vector& array) //Conforming for display
{
for (typename std::vector::size_type i = 1; i < array.size(); ++i)
{
if (array[i] < array[i-1])
{
return false;
}
}
return true;
}
std::vector a (10); //Creates a vector of size 10
int arr[10];
template
void accept(std::vector& array) //Accepts data to a vector
{
int c;
for(c = 0; c < 10; c++)
cin>>arr[c];
a.assign (arr,arr+10); //Assign array data to the vector
}
template
void display(std::vector& array) //Display the vector contents
{
for (std::vector::iterator it = array.begin(); it != array.end(); ++it)
std::cout << ' ' << *it;
}
template
void selection(std::vector& arr) //Selection soring operation
{
int mini, loc, temp, x, y;
mini = arr[0];
for(x = 0; x <= arr.size()-1; x++)
{
mini = arr[x]; //x position value of array is considered as minimum value
loc = x; //Stores the location of the minimum value
for(y = x + 1; y <= arr.size()-1; y++)
{
if(arr[y] < mini) //Checks the already minimum value with the array contents
{
mini = arr[y]; //Stores the new minimum value
loc = y; //Stores the location of the minimum value
}
}
if(loc != x) //If it is not the same location
{
temp = arr[x];
arr[x] = arr[loc];
arr[loc] = temp;
}
}
}
template
void bubble(std::vector &ar) //Bubble sort operation
{
bool swapp = true;
while(swapp)
{
swapp = false;
for (int i = 0; i < ar.size()-1; i++)
{
if (ar[i]>ar[i+1] )
{
ar[i] += ar[i+1];
ar[i+1] = ar[i] - ar[i+1];
ar[i] -=ar[i+1];
swapp = true;
}
}
}
}
int main()
{
char ch;
do
{
cout<<" MENU";
cout<<" a Fill the array with user input";
cout<<" b Display the array";
cout<<" c Suffel the array element randomly";
cout<<" d Sort the array using bubble sort";
cout<<" e Sort the array using Selection Sort";
cout<<" f Exit Program";
cout<<" Enter your choice: ";
cin>>ch;
switch(ch)
{
case 'a':
case 'A':
accept(a);
cout<<" Accept data operation completed  ";
break;
case 'b':
case 'B':
display(a);
cout<<" Display data operation completed  ";
break;
case 'c':
case 'C':
bogosort(a);
bool b = is_sorted(a);
if(b == true)
display(a);
cout<<" Bugg Sorting operation completed  ";
break;
case 'd':
case 'D':
bubble(a);
display(a);
cout<<" Bubble Sort operation completed  ";
break;
case 'e':
case 'E':
selection(a);
display(a);
cout<<" Selection Sort operation completed  ";
break;
case 'f':
case 'F':
exit(0);
default:
cout<<" Wrong Choice";
}
}while(1); //Loop will continue infinitely till F or f is pressed
}
Output
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: a
10
5
4
78
9
65
3
1
45
66
Accept data operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: b
10 5 4 78 9 65 3 1 45 66
Display data operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: c
1 3 4 5 9 10 45 65 66 78
Bugg Sorting operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice:
d
1 3 4 5 9 10 45 65 66 78
Bubble Sort operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: e
1 3 4 5 9 10 45 65 66 78
Selection Sort operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: f
Solution
#include
#include
#include
using namespace std;
template //For Template
void bogosort(std::vector& array) //For bogosort
{
while (! is_sorted(array))
{
std::random_shuffle(array.begin(), array.end());
}
}
template
bool is_sorted(const std::vector& array) //Conforming for display
{
for (typename std::vector::size_type i = 1; i < array.size(); ++i)
{
if (array[i] < array[i-1])
{
return false;
}
}
return true;
}
std::vector a (10); //Creates a vector of size 10
int arr[10];
template
void accept(std::vector& array) //Accepts data to a vector
{
int c;
for(c = 0; c < 10; c++)
cin>>arr[c];
a.assign (arr,arr+10); //Assign array data to the vector
}
template
void display(std::vector& array) //Display the vector contents
{
for (std::vector::iterator it = array.begin(); it != array.end(); ++it)
std::cout << ' ' << *it;
}
template
void selection(std::vector& arr) //Selection soring operation
{
int mini, loc, temp, x, y;
mini = arr[0];
for(x = 0; x <= arr.size()-1; x++)
{
mini = arr[x]; //x position value of array is considered as minimum value
loc = x; //Stores the location of the minimum value
for(y = x + 1; y <= arr.size()-1; y++)
{
if(arr[y] < mini) //Checks the already minimum value with the array contents
{
mini = arr[y]; //Stores the new minimum value
loc = y; //Stores the location of the minimum value
}
}
if(loc != x) //If it is not the same location
{
temp = arr[x];
arr[x] = arr[loc];
arr[loc] = temp;
}
}
}
template
void bubble(std::vector &ar) //Bubble sort operation
{
bool swapp = true;
while(swapp)
{
swapp = false;
for (int i = 0; i < ar.size()-1; i++)
{
if (ar[i]>ar[i+1] )
{
ar[i] += ar[i+1];
ar[i+1] = ar[i] - ar[i+1];
ar[i] -=ar[i+1];
swapp = true;
}
}
}
}
int main()
{
char ch;
do
{
cout<<" MENU";
cout<<" a Fill the array with user input";
cout<<" b Display the array";
cout<<" c Suffel the array element randomly";
cout<<" d Sort the array using bubble sort";
cout<<" e Sort the array using Selection Sort";
cout<<" f Exit Program";
cout<<" Enter your choice: ";
cin>>ch;
switch(ch)
{
case 'a':
case 'A':
accept(a);
cout<<" Accept data operation completed  ";
break;
case 'b':
case 'B':
display(a);
cout<<" Display data operation completed  ";
break;
case 'c':
case 'C':
bogosort(a);
bool b = is_sorted(a);
if(b == true)
display(a);
cout<<" Bugg Sorting operation completed  ";
break;
case 'd':
case 'D':
bubble(a);
display(a);
cout<<" Bubble Sort operation completed  ";
break;
case 'e':
case 'E':
selection(a);
display(a);
cout<<" Selection Sort operation completed  ";
break;
case 'f':
case 'F':
exit(0);
default:
cout<<" Wrong Choice";
}
}while(1); //Loop will continue infinitely till F or f is pressed
}
Output
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: a
10
5
4
78
9
65
3
1
45
66
Accept data operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: b
10 5 4 78 9 65 3 1 45 66
Display data operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: c
1 3 4 5 9 10 45 65 66 78
Bugg Sorting operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice:
d
1 3 4 5 9 10 45 65 66 78
Bubble Sort operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: e
1 3 4 5 9 10 45 65 66 78
Selection Sort operation completed
MENU
a Fill the array with user input
b Display the array
c Suffel the array element randomly
d Sort the array using bubble sort
e Sort the array using Selection Sort
f Exit Program
Enter your choice: f

More Related Content

Similar to #include algorithm #include vector #include iostream usi.pdf

CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
priestmanmable
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
raksharao
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
Husain Dalal
 
Cpl
CplCpl
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
Hi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdfHi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
anandf0099
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
Tony Kurishingal
 
Arrays
ArraysArrays
Qprgs
QprgsQprgs
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
Christian Baranowski
 

Similar to #include algorithm #include vector #include iostream usi.pdf (12)

CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
Cpl
CplCpl
Cpl
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Hi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdfHi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Arrays
ArraysArrays
Arrays
 
Qprgs
QprgsQprgs
Qprgs
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 

More from ssuseraef9da

The empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdfThe empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdf
ssuseraef9da
 
There are two ways to solve this problem. I will .pdf
There are two ways to solve this problem. I will .pdfThere are two ways to solve this problem. I will .pdf
There are two ways to solve this problem. I will .pdf
ssuseraef9da
 
If an oxide has the formula MO, then since O is normally found in th.pdf
If an oxide has the formula MO, then since O is normally found in th.pdfIf an oxide has the formula MO, then since O is normally found in th.pdf
If an oxide has the formula MO, then since O is normally found in th.pdf
ssuseraef9da
 
This is a titration of a weak base w a strong ac.pdf
This is a titration of a weak base w a strong ac.pdfThis is a titration of a weak base w a strong ac.pdf
This is a titration of a weak base w a strong ac.pdf
ssuseraef9da
 
1. True2. I am having trouble understanding the phrasing. A precip.pdf
1. True2. I am having trouble understanding the phrasing. A precip.pdf1. True2. I am having trouble understanding the phrasing. A precip.pdf
1. True2. I am having trouble understanding the phrasing. A precip.pdf
ssuseraef9da
 
1) The main thrust behind the Brexit vote was the fear that UK based.pdf
1) The main thrust behind the Brexit vote was the fear that UK based.pdf1) The main thrust behind the Brexit vote was the fear that UK based.pdf
1) The main thrust behind the Brexit vote was the fear that UK based.pdf
ssuseraef9da
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
ssuseraef9da
 
This is a titration of a weak base w a strong ac.pdf
This is a titration of a weak base w a strong ac.pdfThis is a titration of a weak base w a strong ac.pdf
This is a titration of a weak base w a strong ac.pdf
ssuseraef9da
 
There are two ways to solve this problem. I will .pdf
There are two ways to solve this problem. I will .pdfThere are two ways to solve this problem. I will .pdf
There are two ways to solve this problem. I will .pdf
ssuseraef9da
 
The empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdfThe empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdf
ssuseraef9da
 
1) The main thrust behind the Brexit vote was the fear that UK based.pdf
1) The main thrust behind the Brexit vote was the fear that UK based.pdf1) The main thrust behind the Brexit vote was the fear that UK based.pdf
1) The main thrust behind the Brexit vote was the fear that UK based.pdf
ssuseraef9da
 
The empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdfThe empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdf
ssuseraef9da
 
If an oxide has the formula MO, then since O is normally found in th.pdf
If an oxide has the formula MO, then since O is normally found in th.pdfIf an oxide has the formula MO, then since O is normally found in th.pdf
If an oxide has the formula MO, then since O is normally found in th.pdf
ssuseraef9da
 
1. True2. I am having trouble understanding the phrasing. A precip.pdf
1. True2. I am having trouble understanding the phrasing. A precip.pdf1. True2. I am having trouble understanding the phrasing. A precip.pdf
1. True2. I am having trouble understanding the phrasing. A precip.pdf
ssuseraef9da
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
ssuseraef9da
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
ssuseraef9da
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
ssuseraef9da
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
ssuseraef9da
 

More from ssuseraef9da (18)

The empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdfThe empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdf
 
There are two ways to solve this problem. I will .pdf
There are two ways to solve this problem. I will .pdfThere are two ways to solve this problem. I will .pdf
There are two ways to solve this problem. I will .pdf
 
If an oxide has the formula MO, then since O is normally found in th.pdf
If an oxide has the formula MO, then since O is normally found in th.pdfIf an oxide has the formula MO, then since O is normally found in th.pdf
If an oxide has the formula MO, then since O is normally found in th.pdf
 
This is a titration of a weak base w a strong ac.pdf
This is a titration of a weak base w a strong ac.pdfThis is a titration of a weak base w a strong ac.pdf
This is a titration of a weak base w a strong ac.pdf
 
1. True2. I am having trouble understanding the phrasing. A precip.pdf
1. True2. I am having trouble understanding the phrasing. A precip.pdf1. True2. I am having trouble understanding the phrasing. A precip.pdf
1. True2. I am having trouble understanding the phrasing. A precip.pdf
 
1) The main thrust behind the Brexit vote was the fear that UK based.pdf
1) The main thrust behind the Brexit vote was the fear that UK based.pdf1) The main thrust behind the Brexit vote was the fear that UK based.pdf
1) The main thrust behind the Brexit vote was the fear that UK based.pdf
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
 
This is a titration of a weak base w a strong ac.pdf
This is a titration of a weak base w a strong ac.pdfThis is a titration of a weak base w a strong ac.pdf
This is a titration of a weak base w a strong ac.pdf
 
There are two ways to solve this problem. I will .pdf
There are two ways to solve this problem. I will .pdfThere are two ways to solve this problem. I will .pdf
There are two ways to solve this problem. I will .pdf
 
The empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdfThe empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdf
 
1) The main thrust behind the Brexit vote was the fear that UK based.pdf
1) The main thrust behind the Brexit vote was the fear that UK based.pdf1) The main thrust behind the Brexit vote was the fear that UK based.pdf
1) The main thrust behind the Brexit vote was the fear that UK based.pdf
 
The empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdfThe empirical formula indicates the relative proportions of the elem.pdf
The empirical formula indicates the relative proportions of the elem.pdf
 
If an oxide has the formula MO, then since O is normally found in th.pdf
If an oxide has the formula MO, then since O is normally found in th.pdfIf an oxide has the formula MO, then since O is normally found in th.pdf
If an oxide has the formula MO, then since O is normally found in th.pdf
 
1. True2. I am having trouble understanding the phrasing. A precip.pdf
1. True2. I am having trouble understanding the phrasing. A precip.pdf1. True2. I am having trouble understanding the phrasing. A precip.pdf
1. True2. I am having trouble understanding the phrasing. A precip.pdf
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
 

Recently uploaded

Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
Celine George
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
khuleseema60
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
Celine George
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 

Recently uploaded (20)

Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 

#include algorithm #include vector #include iostream usi.pdf

  • 1. #include #include #include using namespace std; template //For Template void bogosort(std::vector& array) //For bogosort { while (! is_sorted(array)) { std::random_shuffle(array.begin(), array.end()); } } template bool is_sorted(const std::vector& array) //Conforming for display { for (typename std::vector::size_type i = 1; i < array.size(); ++i) { if (array[i] < array[i-1]) { return false; } } return true; } std::vector a (10); //Creates a vector of size 10 int arr[10]; template void accept(std::vector& array) //Accepts data to a vector { int c; for(c = 0; c < 10; c++) cin>>arr[c]; a.assign (arr,arr+10); //Assign array data to the vector } template
  • 2. void display(std::vector& array) //Display the vector contents { for (std::vector::iterator it = array.begin(); it != array.end(); ++it) std::cout << ' ' << *it; } template void selection(std::vector& arr) //Selection soring operation { int mini, loc, temp, x, y; mini = arr[0]; for(x = 0; x <= arr.size()-1; x++) { mini = arr[x]; //x position value of array is considered as minimum value loc = x; //Stores the location of the minimum value for(y = x + 1; y <= arr.size()-1; y++) { if(arr[y] < mini) //Checks the already minimum value with the array contents { mini = arr[y]; //Stores the new minimum value loc = y; //Stores the location of the minimum value } } if(loc != x) //If it is not the same location { temp = arr[x]; arr[x] = arr[loc]; arr[loc] = temp; } } } template void bubble(std::vector &ar) //Bubble sort operation { bool swapp = true; while(swapp) {
  • 3. swapp = false; for (int i = 0; i < ar.size()-1; i++) { if (ar[i]>ar[i+1] ) { ar[i] += ar[i+1]; ar[i+1] = ar[i] - ar[i+1]; ar[i] -=ar[i+1]; swapp = true; } } } } int main() { char ch; do { cout<<" MENU"; cout<<" a Fill the array with user input"; cout<<" b Display the array"; cout<<" c Suffel the array element randomly"; cout<<" d Sort the array using bubble sort"; cout<<" e Sort the array using Selection Sort"; cout<<" f Exit Program"; cout<<" Enter your choice: "; cin>>ch; switch(ch) { case 'a': case 'A': accept(a); cout<<" Accept data operation completed "; break; case 'b': case 'B':
  • 4. display(a); cout<<" Display data operation completed "; break; case 'c': case 'C': bogosort(a); bool b = is_sorted(a); if(b == true) display(a); cout<<" Bugg Sorting operation completed "; break; case 'd': case 'D': bubble(a); display(a); cout<<" Bubble Sort operation completed "; break; case 'e': case 'E': selection(a); display(a); cout<<" Selection Sort operation completed "; break; case 'f': case 'F': exit(0); default: cout<<" Wrong Choice"; } }while(1); //Loop will continue infinitely till F or f is pressed } Output MENU a Fill the array with user input b Display the array
  • 5. c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: a 10 5 4 78 9 65 3 1 45 66 Accept data operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: b 10 5 4 78 9 65 3 1 45 66 Display data operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: c 1 3 4 5 9 10 45 65 66 78 Bugg Sorting operation completed
  • 6. MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: d 1 3 4 5 9 10 45 65 66 78 Bubble Sort operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: e 1 3 4 5 9 10 45 65 66 78 Selection Sort operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: f Solution #include #include #include using namespace std;
  • 7. template //For Template void bogosort(std::vector& array) //For bogosort { while (! is_sorted(array)) { std::random_shuffle(array.begin(), array.end()); } } template bool is_sorted(const std::vector& array) //Conforming for display { for (typename std::vector::size_type i = 1; i < array.size(); ++i) { if (array[i] < array[i-1]) { return false; } } return true; } std::vector a (10); //Creates a vector of size 10 int arr[10]; template void accept(std::vector& array) //Accepts data to a vector { int c; for(c = 0; c < 10; c++) cin>>arr[c]; a.assign (arr,arr+10); //Assign array data to the vector } template void display(std::vector& array) //Display the vector contents { for (std::vector::iterator it = array.begin(); it != array.end(); ++it) std::cout << ' ' << *it; }
  • 8. template void selection(std::vector& arr) //Selection soring operation { int mini, loc, temp, x, y; mini = arr[0]; for(x = 0; x <= arr.size()-1; x++) { mini = arr[x]; //x position value of array is considered as minimum value loc = x; //Stores the location of the minimum value for(y = x + 1; y <= arr.size()-1; y++) { if(arr[y] < mini) //Checks the already minimum value with the array contents { mini = arr[y]; //Stores the new minimum value loc = y; //Stores the location of the minimum value } } if(loc != x) //If it is not the same location { temp = arr[x]; arr[x] = arr[loc]; arr[loc] = temp; } } } template void bubble(std::vector &ar) //Bubble sort operation { bool swapp = true; while(swapp) { swapp = false; for (int i = 0; i < ar.size()-1; i++) { if (ar[i]>ar[i+1] ) {
  • 9. ar[i] += ar[i+1]; ar[i+1] = ar[i] - ar[i+1]; ar[i] -=ar[i+1]; swapp = true; } } } } int main() { char ch; do { cout<<" MENU"; cout<<" a Fill the array with user input"; cout<<" b Display the array"; cout<<" c Suffel the array element randomly"; cout<<" d Sort the array using bubble sort"; cout<<" e Sort the array using Selection Sort"; cout<<" f Exit Program"; cout<<" Enter your choice: "; cin>>ch; switch(ch) { case 'a': case 'A': accept(a); cout<<" Accept data operation completed "; break; case 'b': case 'B': display(a); cout<<" Display data operation completed "; break; case 'c': case 'C':
  • 10. bogosort(a); bool b = is_sorted(a); if(b == true) display(a); cout<<" Bugg Sorting operation completed "; break; case 'd': case 'D': bubble(a); display(a); cout<<" Bubble Sort operation completed "; break; case 'e': case 'E': selection(a); display(a); cout<<" Selection Sort operation completed "; break; case 'f': case 'F': exit(0); default: cout<<" Wrong Choice"; } }while(1); //Loop will continue infinitely till F or f is pressed } Output MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: a
  • 11. 10 5 4 78 9 65 3 1 45 66 Accept data operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: b 10 5 4 78 9 65 3 1 45 66 Display data operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: c 1 3 4 5 9 10 45 65 66 78 Bugg Sorting operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort
  • 12. e Sort the array using Selection Sort f Exit Program Enter your choice: d 1 3 4 5 9 10 45 65 66 78 Bubble Sort operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: e 1 3 4 5 9 10 45 65 66 78 Selection Sort operation completed MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: f