SlideShare a Scribd company logo
1 of 12
Download to read offline
#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 filePranav Ghildiyal
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxpriestmanmable
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contdraksharao
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objectsHusain Dalal
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
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 .pdfanandf0099
 

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 arwholesalelors

Algebra, branch of mathematics in which arithmetical operations and .pdf
Algebra, branch of mathematics in which arithmetical operations and .pdfAlgebra, branch of mathematics in which arithmetical operations and .pdf
Algebra, branch of mathematics in which arithmetical operations and .pdfarwholesalelors
 
AccuracyData accuracy mentions to the degree with which data prop.pdf
AccuracyData accuracy mentions to the degree with which data prop.pdfAccuracyData accuracy mentions to the degree with which data prop.pdf
AccuracyData accuracy mentions to the degree with which data prop.pdfarwholesalelors
 
A) I will look for LP (limited partner) such as Yale Investment fund.pdf
A) I will look for LP (limited partner) such as Yale Investment fund.pdfA) I will look for LP (limited partner) such as Yale Investment fund.pdf
A) I will look for LP (limited partner) such as Yale Investment fund.pdfarwholesalelors
 
1. The Kepler space telescope detects planets and planet candidates .pdf
1. The Kepler space telescope detects planets and planet candidates .pdf1. The Kepler space telescope detects planets and planet candidates .pdf
1. The Kepler space telescope detects planets and planet candidates .pdfarwholesalelors
 
1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf
1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf
1. When cell in S phase is fused with cell in G1 phase, the cell of .pdfarwholesalelors
 
1. A Holds individuals accountable for their actions.2. E. A,B and.pdf
1. A Holds individuals accountable for their actions.2. E. A,B and.pdf1. A Holds individuals accountable for their actions.2. E. A,B and.pdf
1. A Holds individuals accountable for their actions.2. E. A,B and.pdfarwholesalelors
 
EtSH is the strongest acid, so EtS- is the weakest conjugate base. .pdf
  EtSH is the strongest acid, so EtS- is the weakest conjugate base.  .pdf  EtSH is the strongest acid, so EtS- is the weakest conjugate base.  .pdf
EtSH is the strongest acid, so EtS- is the weakest conjugate base. .pdfarwholesalelors
 
Particulars Amount $ Share Holders Funds Com.pdf
     Particulars  Amount $          Share Holders Funds            Com.pdf     Particulars  Amount $          Share Holders Funds            Com.pdf
Particulars Amount $ Share Holders Funds Com.pdfarwholesalelors
 
The Nitro group is electron withdrawing, and ther.pdf
                     The Nitro group is electron withdrawing, and ther.pdf                     The Nitro group is electron withdrawing, and ther.pdf
The Nitro group is electron withdrawing, and ther.pdfarwholesalelors
 
The Systems Development Life Cycle Moderate and large firms with uni.pdf
The Systems Development Life Cycle Moderate and large firms with uni.pdfThe Systems Development Life Cycle Moderate and large firms with uni.pdf
The Systems Development Life Cycle Moderate and large firms with uni.pdfarwholesalelors
 
You are asked to determine DNA content of a liver tissue. Describe h.pdf
You are asked to determine DNA content of a liver tissue. Describe h.pdfYou are asked to determine DNA content of a liver tissue. Describe h.pdf
You are asked to determine DNA content of a liver tissue. Describe h.pdfarwholesalelors
 
when we draw a vertical line it will cross the graph twice(that is m.pdf
when we draw a vertical line it will cross the graph twice(that is m.pdfwhen we draw a vertical line it will cross the graph twice(that is m.pdf
when we draw a vertical line it will cross the graph twice(that is m.pdfarwholesalelors
 
We Know that      Baking powder and Baking soda isused as a leave.pdf
We Know that      Baking powder and Baking soda isused as a leave.pdfWe Know that      Baking powder and Baking soda isused as a leave.pdf
We Know that      Baking powder and Baking soda isused as a leave.pdfarwholesalelors
 
The fallowing program shows the simple transformation #define GLEW.pdf
The fallowing program shows the simple transformation #define GLEW.pdfThe fallowing program shows the simple transformation #define GLEW.pdf
The fallowing program shows the simple transformation #define GLEW.pdfarwholesalelors
 
Two types of malware -1. Virus A virus is a contagious program o.pdf
Two types of malware -1. Virus A virus is a contagious program o.pdfTwo types of malware -1. Virus A virus is a contagious program o.pdf
Two types of malware -1. Virus A virus is a contagious program o.pdfarwholesalelors
 
TlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdf
TlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdfTlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdf
TlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdfarwholesalelors
 
The cells of the reproductive organs (Eg ovaries ad testes) undergo.pdf
The cells of the reproductive organs (Eg ovaries ad testes) undergo.pdfThe cells of the reproductive organs (Eg ovaries ad testes) undergo.pdf
The cells of the reproductive organs (Eg ovaries ad testes) undergo.pdfarwholesalelors
 
Scientific evidences I would give in support of evolution1. Paleo.pdf
Scientific evidences I would give in support of evolution1. Paleo.pdfScientific evidences I would give in support of evolution1. Paleo.pdf
Scientific evidences I would give in support of evolution1. Paleo.pdfarwholesalelors
 
Package scopeis the range of visibility for aparticular element or c.pdf
Package scopeis the range of visibility for aparticular element or c.pdfPackage scopeis the range of visibility for aparticular element or c.pdf
Package scopeis the range of visibility for aparticular element or c.pdfarwholesalelors
 
Point of zero charge related to the adsorption phenomenon I surface .pdf
Point of zero charge related to the adsorption phenomenon I surface .pdfPoint of zero charge related to the adsorption phenomenon I surface .pdf
Point of zero charge related to the adsorption phenomenon I surface .pdfarwholesalelors
 

More from arwholesalelors (20)

Algebra, branch of mathematics in which arithmetical operations and .pdf
Algebra, branch of mathematics in which arithmetical operations and .pdfAlgebra, branch of mathematics in which arithmetical operations and .pdf
Algebra, branch of mathematics in which arithmetical operations and .pdf
 
AccuracyData accuracy mentions to the degree with which data prop.pdf
AccuracyData accuracy mentions to the degree with which data prop.pdfAccuracyData accuracy mentions to the degree with which data prop.pdf
AccuracyData accuracy mentions to the degree with which data prop.pdf
 
A) I will look for LP (limited partner) such as Yale Investment fund.pdf
A) I will look for LP (limited partner) such as Yale Investment fund.pdfA) I will look for LP (limited partner) such as Yale Investment fund.pdf
A) I will look for LP (limited partner) such as Yale Investment fund.pdf
 
1. The Kepler space telescope detects planets and planet candidates .pdf
1. The Kepler space telescope detects planets and planet candidates .pdf1. The Kepler space telescope detects planets and planet candidates .pdf
1. The Kepler space telescope detects planets and planet candidates .pdf
 
1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf
1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf
1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf
 
1. A Holds individuals accountable for their actions.2. E. A,B and.pdf
1. A Holds individuals accountable for their actions.2. E. A,B and.pdf1. A Holds individuals accountable for their actions.2. E. A,B and.pdf
1. A Holds individuals accountable for their actions.2. E. A,B and.pdf
 
EtSH is the strongest acid, so EtS- is the weakest conjugate base. .pdf
  EtSH is the strongest acid, so EtS- is the weakest conjugate base.  .pdf  EtSH is the strongest acid, so EtS- is the weakest conjugate base.  .pdf
EtSH is the strongest acid, so EtS- is the weakest conjugate base. .pdf
 
Particulars Amount $ Share Holders Funds Com.pdf
     Particulars  Amount $          Share Holders Funds            Com.pdf     Particulars  Amount $          Share Holders Funds            Com.pdf
Particulars Amount $ Share Holders Funds Com.pdf
 
The Nitro group is electron withdrawing, and ther.pdf
                     The Nitro group is electron withdrawing, and ther.pdf                     The Nitro group is electron withdrawing, and ther.pdf
The Nitro group is electron withdrawing, and ther.pdf
 
The Systems Development Life Cycle Moderate and large firms with uni.pdf
The Systems Development Life Cycle Moderate and large firms with uni.pdfThe Systems Development Life Cycle Moderate and large firms with uni.pdf
The Systems Development Life Cycle Moderate and large firms with uni.pdf
 
You are asked to determine DNA content of a liver tissue. Describe h.pdf
You are asked to determine DNA content of a liver tissue. Describe h.pdfYou are asked to determine DNA content of a liver tissue. Describe h.pdf
You are asked to determine DNA content of a liver tissue. Describe h.pdf
 
when we draw a vertical line it will cross the graph twice(that is m.pdf
when we draw a vertical line it will cross the graph twice(that is m.pdfwhen we draw a vertical line it will cross the graph twice(that is m.pdf
when we draw a vertical line it will cross the graph twice(that is m.pdf
 
We Know that      Baking powder and Baking soda isused as a leave.pdf
We Know that      Baking powder and Baking soda isused as a leave.pdfWe Know that      Baking powder and Baking soda isused as a leave.pdf
We Know that      Baking powder and Baking soda isused as a leave.pdf
 
The fallowing program shows the simple transformation #define GLEW.pdf
The fallowing program shows the simple transformation #define GLEW.pdfThe fallowing program shows the simple transformation #define GLEW.pdf
The fallowing program shows the simple transformation #define GLEW.pdf
 
Two types of malware -1. Virus A virus is a contagious program o.pdf
Two types of malware -1. Virus A virus is a contagious program o.pdfTwo types of malware -1. Virus A virus is a contagious program o.pdf
Two types of malware -1. Virus A virus is a contagious program o.pdf
 
TlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdf
TlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdfTlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdf
TlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdf
 
The cells of the reproductive organs (Eg ovaries ad testes) undergo.pdf
The cells of the reproductive organs (Eg ovaries ad testes) undergo.pdfThe cells of the reproductive organs (Eg ovaries ad testes) undergo.pdf
The cells of the reproductive organs (Eg ovaries ad testes) undergo.pdf
 
Scientific evidences I would give in support of evolution1. Paleo.pdf
Scientific evidences I would give in support of evolution1. Paleo.pdfScientific evidences I would give in support of evolution1. Paleo.pdf
Scientific evidences I would give in support of evolution1. Paleo.pdf
 
Package scopeis the range of visibility for aparticular element or c.pdf
Package scopeis the range of visibility for aparticular element or c.pdfPackage scopeis the range of visibility for aparticular element or c.pdf
Package scopeis the range of visibility for aparticular element or c.pdf
 
Point of zero charge related to the adsorption phenomenon I surface .pdf
Point of zero charge related to the adsorption phenomenon I surface .pdfPoint of zero charge related to the adsorption phenomenon I surface .pdf
Point of zero charge related to the adsorption phenomenon I surface .pdf
 

Recently uploaded

Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsPallavi Parmar
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfKartik Tiwari
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfElizabeth Walsh
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 

Recently uploaded (20)

Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell Tolls
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.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