0% found this document useful (0 votes)
36 views4 pages

Bubble Sort: Output

The document describes the bubble sort algorithm. It includes code to implement bubble sort on both integer and character arrays. The code contains nested for loops to iterate through the arrays and swap adjacent elements if they are out of order. The main function initializes some sample arrays, calls the bubble sort function on them, and prints the sorted arrays.

Uploaded by

Shawn Rodriguez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

Bubble Sort: Output

The document describes the bubble sort algorithm. It includes code to implement bubble sort on both integer and character arrays. The code contains nested for loops to iterate through the arrays and swap adjacent elements if they are out of order. The main function initializes some sample arrays, calls the bubble sort function on them, and prints the sorted arrays.

Uploaded by

Shawn Rodriguez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Bubble sort

#include<conio.h>
#include<iostream.h>
template<class bubble>
void bubble(bubble a[], int n)
{
int i, j;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
bubble element;
element = a[i];
a[i] = a[j];
a[j] = element;
}
}
}}
void main()
{
int a[6]={1,2,3,4,4,3};
char b[4]={'s','b','d','e'};
clrscr();
bubble(a,6);
cout<<"\nSorted Order Integers: ";
for(int i=0;i<6;i++)
cout<<a[i]<<"\t";
bubble(b,4);
cout<<"\nSorted Order Characters: ";
for(int j=0;j<4;j++)
cout<<b[j]<<"\t";
getch();
}

Output:

Selection Sort
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[100],i,n,p,k,min,loc,temp;
cout<<"\n------------ SELECTION SORT ------------ \n\n" ;
cout<<"Enter No. of Elements=";
cin>>n;
cout<<"\nEnter Elements=\n";
for(i=1;i<=n;i++)
{
cin>>a[i];
}
for(p=1;p<=n-1;p++)
{
min=a[p];
loc=p;

// Loop for Pass

for(k=p+1;k<=n;k++)
{
if(min>a[k])
{
min=a[k];
loc=k;
}
}

// Finding Min Value

temp=a[p];
and Min Value
a[p]=a[loc];
a[loc]=temp;
}
cout<<"\nAfter Sorting : \n";
for(i=1;i<=n;i++)
{
cout<<a[i]<<endl;
}

// Element Selection

// Swap Selected Element

getch();
}

Output :-

You might also like