Dsa Assign 9
Dsa Assign 9
#include <iostream>
#define MAX 5
using namespace std;
//////////////////////
void BUBBLE_SORT(int A[], int N){
int round, i, temp;
for(int round = 0; round < N; round++){
for(i = 0; i <= (N-1-round); i++){
if(A[i] > A[i+1]){
temp = A[i];
A[i] = A[i+1];
A[i+1] = temp;
}
}
}
}
//////////////////////
int main(){
int A[]={5, 8, 3, 2, 9};
int K;
BUBBLE_SORT(A, MAX);
cout<<endl;
return 0;
}
Q2:-
#include <iostream>
using namespace std;
//////////////////////
int MIN(int A[], int K, int N){
int j, LOC, MIN;
MIN = A[K];
LOC = K;
for(j = K; j <= N-1; j++){
if(MIN > A[j]){
MIN = A[j];
LOC = j;
}
}
return LOC;
}
/////////////////////
void SELECTION_SORT(int A[], int N){
int LOC, K, temp;
for(K = 0; K < N; K++){
LOC = MIN(A, K, N);
temp = A[K];
A[K] = A[LOC];
A[LOC] = temp;
}
}
////////////////////
int main(){
int A[]={5, 8, 3, 2, 9};
int K;
SELECTION_SORT(A, 5);
for(K = 0; K < 5; K++){
cout<<A[K]<<"\t";
}
cout<<endl;
cout<<endl;
return 0;
}