SlideShare a Scribd company logo
1 of 2
// Group B-Assignment Selection Sort Using Templates.
#include<iostream> //input output stream
#define size 10 //
using namespace std;
int n; //global variable declaration
template<class T> //T Typename -carry all datatypes
void selection(T A[size]) //T-int array and float array
{
int i,j,min; //0,1,2,3,4....
T temp; //swap int and float
for(i=0;i<n;i++) //pass 1 ,2,3....
{ min=i; // (2,14,23,1,19)
for(j=i+1;j<n;j++) //comapring 2 elements
{ if(A[j]<A[min])
min=j;
}
temp=A[i];
A[i]=A[min];
A[min]=temp;
}
cout<<"n The sorted list is:.../n";
for(i=0;i<n;i++)
cout<<"t"<<A[i];
}
int main()
{
int i,A[size]; // int type array
float B[size]; //float array
cout<<"nttSelection Sortn";
cout<<"ntHandling Interger Elements";
cout<<"nHow Many Elements Are There???";
cin>>n;
cout<<"nEnter the integer numbers";
for(i=0;i<n;i++)
cin>>A[i];
selection(A); //template function calling for Int array
cout<<"nttHandling Float Elementsn";
cout<<"nHow Many Elements Are There???n";
cin>>n;
cout<<"n Enter the Float numbers";
for(i=0;i<n;i++)
cin>>B[i];
selection(B); //template function calling for float array
cout<<"n";
return 0;
}

More Related Content

Similar to selection sort.docx

Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
Saad Gabr
 
Need this in JAVA We have N numbers as an array, you need to find a .pdf
Need this in JAVA We have N numbers as an array, you need to find a .pdfNeed this in JAVA We have N numbers as an array, you need to find a .pdf
Need this in JAVA We have N numbers as an array, you need to find a .pdf
arorastores
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
Nooryaseen9
 

Similar to selection sort.docx (20)

Oop assignment 02
Oop assignment 02Oop assignment 02
Oop assignment 02
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency API
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 
Computer Programming- Lecture 7
Computer Programming- Lecture 7Computer Programming- Lecture 7
Computer Programming- Lecture 7
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
import java-lang-Comparable- -- new Main-String-() public class Main-.pdf
import java-lang-Comparable-  -- new Main-String-() public class Main-.pdfimport java-lang-Comparable-  -- new Main-String-() public class Main-.pdf
import java-lang-Comparable- -- new Main-String-() public class Main-.pdf
 
Lec2&3_DataStructure
Lec2&3_DataStructureLec2&3_DataStructure
Lec2&3_DataStructure
 
Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
 
Lec2
Lec2Lec2
Lec2
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
Assignment
AssignmentAssignment
Assignment
 
Need this in JAVA We have N numbers as an array, you need to find a .pdf
Need this in JAVA We have N numbers as an array, you need to find a .pdfNeed this in JAVA We have N numbers as an array, you need to find a .pdf
Need this in JAVA We have N numbers as an array, you need to find a .pdf
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 
c programming
c programmingc programming
c programming
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPG
 

Recently uploaded

ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Lovely Professional University
 
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
MohammadAliNayeem
 

Recently uploaded (20)

BURGER ORDERING SYSYTEM PROJECT REPORT..pdf
BURGER ORDERING SYSYTEM PROJECT REPORT..pdfBURGER ORDERING SYSYTEM PROJECT REPORT..pdf
BURGER ORDERING SYSYTEM PROJECT REPORT..pdf
 
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
Dairy management system project report..pdf
Dairy management system project report..pdfDairy management system project report..pdf
Dairy management system project report..pdf
 
Introduction to Heat Exchangers: Principle, Types and Applications
Introduction to Heat Exchangers: Principle, Types and ApplicationsIntroduction to Heat Exchangers: Principle, Types and Applications
Introduction to Heat Exchangers: Principle, Types and Applications
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
Circuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineeringCircuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineering
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
Theory for How to calculation capacitor bank
Theory for How to calculation capacitor bankTheory for How to calculation capacitor bank
Theory for How to calculation capacitor bank
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
 
Quiz application system project report..pdf
Quiz application system project report..pdfQuiz application system project report..pdf
Quiz application system project report..pdf
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
 

selection sort.docx

  • 1. // Group B-Assignment Selection Sort Using Templates. #include<iostream> //input output stream #define size 10 // using namespace std; int n; //global variable declaration template<class T> //T Typename -carry all datatypes void selection(T A[size]) //T-int array and float array { int i,j,min; //0,1,2,3,4.... T temp; //swap int and float for(i=0;i<n;i++) //pass 1 ,2,3.... { min=i; // (2,14,23,1,19) for(j=i+1;j<n;j++) //comapring 2 elements { if(A[j]<A[min]) min=j; } temp=A[i]; A[i]=A[min]; A[min]=temp; } cout<<"n The sorted list is:.../n"; for(i=0;i<n;i++) cout<<"t"<<A[i]; } int main() { int i,A[size]; // int type array float B[size]; //float array cout<<"nttSelection Sortn"; cout<<"ntHandling Interger Elements"; cout<<"nHow Many Elements Are There???"; cin>>n; cout<<"nEnter the integer numbers"; for(i=0;i<n;i++) cin>>A[i]; selection(A); //template function calling for Int array cout<<"nttHandling Float Elementsn"; cout<<"nHow Many Elements Are There???n"; cin>>n; cout<<"n Enter the Float numbers"; for(i=0;i<n;i++) cin>>B[i]; selection(B); //template function calling for float array