-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnandSort.cpp
More file actions
26 lines (26 loc) · 805 Bytes
/
AnandSort.cpp
File metadata and controls
26 lines (26 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* This Sorting Algorith is based on array index matching, if element matches with the index number then that element is assigned at that place or index of array */
/* if we will assign each element at unique index and then print array in increasing order, ofcorse element will be printed in ascending order.
#include<iostream>
using namespace std;
int main(){
int i,j,n,A[100]={0}; // Initally each index is assigned with 0
cout<<"Enter Size Of the Array: ";
cin>>n;
int B[n];
cout<<"Enter elements: ";
for(i=0;i<n;i++){
cin>>B[i]; }
for(i=0;i<n;i++){
for(j=0;j<=100;j++){
if(B[i]==j){
A[j]=B[i];
break;
}
}
}
for(i=0;i<100;i++){
if(A[i]!=0){ //It will print only that index element value which is not having 0
cout<<A[i]<<" "; }
}
return 0;
}