SlideShare a Scribd company logo
1 of 6
Insertin
int main()
{ int
a[16],i,j,k,temp,n;
cout<<"enter
number of
elements ";
cin>>n;
cout<<"enter the
elementsn";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=1;i<n;i++)
{
for(j=i;j>=1;j--)
{
if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
else
break;
}
}
cout<<"sorted
arrayn"<<endl;
for(k=0;k<n;k++)
{
cout<<a[k]<<endl;
}
return 0;
}
Selection
int main()
{
int data[10],temp,i,n;
cout<<"Enter number of
elementsn";
cin>>n;
cout<<"Enter integersn";
for (i = 0; i < n; i++)
cin>>data[i];
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(data[i]<data[j])
{
temp=data[i];
data[i]=data[j];
data[j]=temp;
}
cout<<"nSorted Array Is";
for(int i=0;i<n;i++)
cout<<"n"<<data[i];
cout<<endl;
return 0;
}
Bubble
int main()
{
int s,temp,i,j,a[20];
cout<<"Enter total numbers of
elements: ";
cin>>s;
cout<<"Enter elements: ";
for(i=0;i<s;i++)
cin>>a[i];
//Bubble sorting algorithm
for(i=s-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"After sorting: "<<endl;
for(i=0;i<s;i++)
cout<<a[i]<<endl;
return 0;
}
Merg
#include<iostream>
#include<conio.h>
using namespace
std;
void mergesort(int
*,int,int);
void merge(int
*,int,int,int);
int a[20],i,n,b[20];
main()
{
cout <<"n enter no
of elements";
cin >> n;
cout <<"enter the
elements";
for(i=0;i<n;i++)
cin >> a[i];
mergesort(a,0,n-1);
cout <<" numbers
after sort";
for(i=0;i<n;i++)
cout << a[i] << " ";
getch();
}
Stack
#include <iostream>
#define STACKSIZE 10
using namespace std;
int Top=-1;
int Stack[STACKSIZE];
void Push(int);
int Pop(void);
bool IsEmpty(void);
bool IsFull(void);
void Traverse(void);
int main( )
{ int item, choice;
while( 1 )
{
cout<< "nnnnn";
cout<< " ******* STACK OPERATIONS
********* nn";
cout<< " 1- Push item n 2- Pop Item n";
cout<< " 3- Traverse / Display Stack Items
n 4- Exit.";
cout<< " nnt Your choice ---> ";
cin>> choice;
switch(choice)
{ case 1: if(IsFull())
cout<< "n Stack Full/Overflown";
void mergesort(int
a[],int i,int j)
{
int mid;
if(i<j)
{
mid=(i+j)/2;
mergesort(a,i,mid);
mergesort(a,mid+1,j
);
merge(a,i,mid,j);
}
}
void merge(int a[],int
low,int mid ,int high)
{
int h,i,j,k;
h=low;
i=low;
j=mid+1;
while(h<=mid &&
j<=high)
{
if(a[h]<=a[j])
b[i]=a[h++];
else
else
{ cout<< "n Enter a number: ";
cin>>item;
Push(item); }
break;
case 2: if(IsEmpty())
cout<< "n Stack is empty) n";
else
{
item=Pop();
cout<< "n deleted from Stack =
"<<item<<endl;
}
break;
case 3: if(IsEmpty())
cout<< "n Stack is empty) n";
else
{
cout<< "n List of Item pushed on
Stack:n";
Traverse();
}
break;
case 4: exit(0);
default:
cout<< "nnt Invalid Choice: n";
b[i]=a[j++];
i++;
}
if( h > mid)
for(k=j;k<=high;k++)
b[i++]=a[k];
else
for(k=h;k<=mid;k++)
b[i++]=a[k];
cout <<"n";
for(k=low;k<=high;k
++)
{ a[k]=b[k];
cout << a[k] <<" ";
}
}
}
}
}
void Push(int item)
{
Stack[++Top] = item;
}
int Pop( )
{
return Stack[Top--];
}
bool IsEmpty( )
{ if(Top == -1 )
return true ;
else
return false;
}
bool IsFull( )
{ if(Top == STACKSIZE-1 )
return true;
else
return false;
}
void Traverse( )
{ int TopTemp = Top;
do
{
cout<< Stack[TopTemp--]<<endl;
}
while(TopTemp>= 0);
}
do
{
cout<< Stack[TopTemp--]<<endl;
}
while(TopTemp>= 0);
}

More Related Content

What's hot

Array using recursion
Array using recursionArray using recursion
Array using recursionSwarup Boro
 
Modificacion del programa
Modificacion del programaModificacion del programa
Modificacion del programaMario José
 
1 borland c++ 5.02 by aramse
1   borland c++ 5.02 by aramse1   borland c++ 5.02 by aramse
1 borland c++ 5.02 by aramseAram SE
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)Takayuki Goto
 
C Programming :- An Example
C Programming :- An Example C Programming :- An Example
C Programming :- An Example Atit Gaonkar
 
The Ring programming language version 1.4 book - Part 18 of 30
The Ring programming language version 1.4 book - Part 18 of 30The Ring programming language version 1.4 book - Part 18 of 30
The Ring programming language version 1.4 book - Part 18 of 30Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184Mahmoud Samir Fayed
 
Data structure programs in c++
Data structure programs in c++Data structure programs in c++
Data structure programs in c++mmirfan
 
The Ring programming language version 1.5.1 book - Part 63 of 180
The Ring programming language version 1.5.1 book - Part 63 of 180The Ring programming language version 1.5.1 book - Part 63 of 180
The Ring programming language version 1.5.1 book - Part 63 of 180Mahmoud Samir Fayed
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03Nasir Mehmood
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202Mahmoud Samir Fayed
 
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловАсинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловYandex
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196Mahmoud Samir Fayed
 
OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++Allan Sun
 
Oops practical file
Oops practical fileOops practical file
Oops practical fileAnkit Dixit
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojureRoy Rutto
 
The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 67 of 185
The Ring programming language version 1.5.4 book - Part 67 of 185The Ring programming language version 1.5.4 book - Part 67 of 185
The Ring programming language version 1.5.4 book - Part 67 of 185Mahmoud Samir Fayed
 

What's hot (20)

Array using recursion
Array using recursionArray using recursion
Array using recursion
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Ada file
Ada fileAda file
Ada file
 
Modificacion del programa
Modificacion del programaModificacion del programa
Modificacion del programa
 
1 borland c++ 5.02 by aramse
1   borland c++ 5.02 by aramse1   borland c++ 5.02 by aramse
1 borland c++ 5.02 by aramse
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
C Programming :- An Example
C Programming :- An Example C Programming :- An Example
C Programming :- An Example
 
The Ring programming language version 1.4 book - Part 18 of 30
The Ring programming language version 1.4 book - Part 18 of 30The Ring programming language version 1.4 book - Part 18 of 30
The Ring programming language version 1.4 book - Part 18 of 30
 
The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184
 
Data structure programs in c++
Data structure programs in c++Data structure programs in c++
Data structure programs in c++
 
The Ring programming language version 1.5.1 book - Part 63 of 180
The Ring programming language version 1.5.1 book - Part 63 of 180The Ring programming language version 1.5.1 book - Part 63 of 180
The Ring programming language version 1.5.1 book - Part 63 of 180
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202
 
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловАсинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196
 
OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++
 
Oops practical file
Oops practical fileOops practical file
Oops practical file
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojure
 
The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189
 
The Ring programming language version 1.5.4 book - Part 67 of 185
The Ring programming language version 1.5.4 book - Part 67 of 185The Ring programming language version 1.5.4 book - Part 67 of 185
The Ring programming language version 1.5.4 book - Part 67 of 185
 

Viewers also liked

Viewers also liked (18)

INSTITUTO TECNOLOGICO SUPERIOR VIDA NUEVA
INSTITUTO TECNOLOGICO SUPERIOR VIDA NUEVAINSTITUTO TECNOLOGICO SUPERIOR VIDA NUEVA
INSTITUTO TECNOLOGICO SUPERIOR VIDA NUEVA
 
Partes internas del PC
Partes internas del PCPartes internas del PC
Partes internas del PC
 
Components of OD by Priyanka & Shephali
Components of OD  by Priyanka & ShephaliComponents of OD  by Priyanka & Shephali
Components of OD by Priyanka & Shephali
 
Partes internas y externas del PC
Partes internas y externas del PCPartes internas y externas del PC
Partes internas y externas del PC
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
Stack
StackStack
Stack
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Register introduction
Register introductionRegister introduction
Register introduction
 
Merge sort lab mannual
Merge sort lab mannualMerge sort lab mannual
Merge sort lab mannual
 
Segment registers
Segment registersSegment registers
Segment registers
 
Queues
QueuesQueues
Queues
 
ملٹی لیول کے شے۔
ملٹی لیول کے شے۔ملٹی لیول کے شے۔
ملٹی لیول کے شے۔
 
Cacheorginization
Cacheorginization Cacheorginization
Cacheorginization
 
Statistics
Statistics Statistics
Statistics
 
Register organisation
Register organisationRegister organisation
Register organisation
 
Memory segmentations
Memory  segmentations Memory  segmentations
Memory segmentations
 
Cache memory
Cache memoryCache memory
Cache memory
 
Array data structure
Array data structureArray data structure
Array data structure
 

Similar to Sortings

Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
COA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfCOA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfJavedAnsari236392
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1kkkseld
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfapexelectronices01
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsVishvjeet Yadav
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfshreeaadithyaacellso
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)Ankit Gupta
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Problem Solving using codes Strings-Extra.pptx
Problem Solving using codes Strings-Extra.pptxProblem Solving using codes Strings-Extra.pptx
Problem Solving using codes Strings-Extra.pptxhappycocoman
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Matlab assignment
Matlab assignmentMatlab assignment
Matlab assignmentRutvik
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfHIMANSUKUMAR12
 

Similar to Sortings (20)

Sorting programs
Sorting programsSorting programs
Sorting programs
 
COA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfCOA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdf
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
Abebe1
Abebe1Abebe1
Abebe1
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
 
Code
CodeCode
Code
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
project3
project3project3
project3
 
C programs
C programsC programs
C programs
 
Problem Solving using codes Strings-Extra.pptx
Problem Solving using codes Strings-Extra.pptxProblem Solving using codes Strings-Extra.pptx
Problem Solving using codes Strings-Extra.pptx
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Aa
AaAa
Aa
 
Matlab assignment
Matlab assignmentMatlab assignment
Matlab assignment
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
C programs
C programsC programs
C programs
 

More from maamir farooq (20)

Ooad lab1
Ooad lab1Ooad lab1
Ooad lab1
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Php client libray
Php client librayPhp client libray
Php client libray
 
Swiftmailer
SwiftmailerSwiftmailer
Swiftmailer
 
Lect15
Lect15Lect15
Lect15
 
Lec 7
Lec 7Lec 7
Lec 7
 
Lec 6
Lec 6Lec 6
Lec 6
 
Lec 5
Lec 5Lec 5
Lec 5
 
J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheet
 
Assignment
AssignmentAssignment
Assignment
 
Java script summary
Java script summaryJava script summary
Java script summary
 
Lec 3
Lec 3Lec 3
Lec 3
 
Lec 2
Lec 2Lec 2
Lec 2
 
Lec 1
Lec 1Lec 1
Lec 1
 
Css summary
Css summaryCss summary
Css summary
 
Manual of image processing lab
Manual of image processing labManual of image processing lab
Manual of image processing lab
 
Session management
Session managementSession management
Session management
 
Data management
Data managementData management
Data management
 
Content provider
Content providerContent provider
Content provider
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 

Sortings

  • 1. Insertin int main() { int a[16],i,j,k,temp,n; cout<<"enter number of elements "; cin>>n; cout<<"enter the elementsn"; for(i=0;i<n;i++) { cin>>a[i]; } for(i=1;i<n;i++) { for(j=i;j>=1;j--) { if(a[j]<a[j-1]) { temp=a[j]; a[j]=a[j-1]; a[j-1]=temp; } else break; } } cout<<"sorted arrayn"<<endl; for(k=0;k<n;k++) { cout<<a[k]<<endl; } return 0; } Selection int main() { int data[10],temp,i,n; cout<<"Enter number of elementsn"; cin>>n; cout<<"Enter integersn"; for (i = 0; i < n; i++) cin>>data[i]; for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) if(data[i]<data[j]) { temp=data[i]; data[i]=data[j]; data[j]=temp; } cout<<"nSorted Array Is"; for(int i=0;i<n;i++) cout<<"n"<<data[i]; cout<<endl; return 0; } Bubble int main() { int s,temp,i,j,a[20]; cout<<"Enter total numbers of elements: "; cin>>s; cout<<"Enter elements: "; for(i=0;i<s;i++) cin>>a[i]; //Bubble sorting algorithm for(i=s-2;i>=0;i--) { for(j=0;j<=i;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } cout<<"After sorting: "<<endl; for(i=0;i<s;i++) cout<<a[i]<<endl; return 0; }
  • 2. Merg #include<iostream> #include<conio.h> using namespace std; void mergesort(int *,int,int); void merge(int *,int,int,int); int a[20],i,n,b[20]; main() { cout <<"n enter no of elements"; cin >> n; cout <<"enter the elements"; for(i=0;i<n;i++) cin >> a[i]; mergesort(a,0,n-1); cout <<" numbers after sort"; for(i=0;i<n;i++) cout << a[i] << " "; getch(); } Stack #include <iostream> #define STACKSIZE 10 using namespace std; int Top=-1; int Stack[STACKSIZE]; void Push(int); int Pop(void); bool IsEmpty(void); bool IsFull(void); void Traverse(void); int main( ) { int item, choice; while( 1 ) { cout<< "nnnnn"; cout<< " ******* STACK OPERATIONS ********* nn"; cout<< " 1- Push item n 2- Pop Item n"; cout<< " 3- Traverse / Display Stack Items n 4- Exit."; cout<< " nnt Your choice ---> "; cin>> choice; switch(choice) { case 1: if(IsFull()) cout<< "n Stack Full/Overflown";
  • 3. void mergesort(int a[],int i,int j) { int mid; if(i<j) { mid=(i+j)/2; mergesort(a,i,mid); mergesort(a,mid+1,j ); merge(a,i,mid,j); } } void merge(int a[],int low,int mid ,int high) { int h,i,j,k; h=low; i=low; j=mid+1; while(h<=mid && j<=high) { if(a[h]<=a[j]) b[i]=a[h++]; else else { cout<< "n Enter a number: "; cin>>item; Push(item); } break; case 2: if(IsEmpty()) cout<< "n Stack is empty) n"; else { item=Pop(); cout<< "n deleted from Stack = "<<item<<endl; } break; case 3: if(IsEmpty()) cout<< "n Stack is empty) n"; else { cout<< "n List of Item pushed on Stack:n"; Traverse(); } break; case 4: exit(0); default: cout<< "nnt Invalid Choice: n";
  • 4. b[i]=a[j++]; i++; } if( h > mid) for(k=j;k<=high;k++) b[i++]=a[k]; else for(k=h;k<=mid;k++) b[i++]=a[k]; cout <<"n"; for(k=low;k<=high;k ++) { a[k]=b[k]; cout << a[k] <<" "; } } } } } void Push(int item) { Stack[++Top] = item; } int Pop( ) { return Stack[Top--]; } bool IsEmpty( ) { if(Top == -1 ) return true ; else return false; } bool IsFull( ) { if(Top == STACKSIZE-1 ) return true; else return false; } void Traverse( ) { int TopTemp = Top;