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

A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
 
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)
 
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
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
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
 
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
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
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
 

Recently uploaded (20)

A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
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)
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.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...
 
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
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
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
 

#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