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 BackPack3

#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 
#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
BackPack3
 

More from BackPack3 (11)

#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
 
#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
 
#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

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
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
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
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
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
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
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
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
 

Recently uploaded (20)

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
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
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
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...
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
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 ...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
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
 

#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