Professional Documents
Culture Documents
Vs Code by Me
Vs Code by Me
Vs Code by Me
for(int j=0;j<arrayLength;j++){
mi=j;
for(i=j+1;i<arrayLength-1;i++){
if (mainarr[i] < mainarr[mi]){
mi=i;
}
}
int t=mainarr[j];
mainarr[j]=mainarr[mi];
mainarr[mi]=t;
}
for(int i=0;i<arrayLength;i++){
cout<< mainarr[i]<<"\n";
}
}
void bubbleSort(int mainarr[10]){
}
void insertionSort(int mainarr[10]){
}
main() {
//Input//
int x;
//int arrayLength;
int numToSearch,arrayLength,numToAdd;
cout <<"Enter The Length Of Array:";
cin >> arrayLength;
// x=arrayLength;
int mainarr[arrayLength];
cout <<"Enter The Numbers To Add In Array:";
for(int i=0;i<arrayLength;i++){
cin >>mainarr[i];
}
//Choose Sort Algorithm//
cout <<"Press 1 for Selection Sort:2 for Bubble Sort:3 for Insertion Sort:";
int n;
cin >> n;
if(n==1){
selectionSort(mainarr);
}
else if(n==2){
bubbleSort(mainarr);
}
else(n==3);{
insertionSort(mainarr);
}
}
//Program Exit Code (pogram will exit instantly without showing final output
without this code)//
cout<<"Proccess Finished,Press Any Key To Exit!";
int ex;
cin>>ex;
}
//////////////////////////////////////////////////////////////////////////
#include <iostream>
using namespace std;
int main() {
int n, i;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (i = 0; i < n; i++) {
cin >> arr[i];
}
bubbleSort(arr, n);
cout << "Array after bubble sort: ";
for (i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
selectionSort(arr, n);
cout << "Array after selection sort: ";
for (i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
insertSort(arr, n);
cout << "Array after insertion sort: ";
for (i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}