-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab4(a)Q5.cpp
More file actions
44 lines (43 loc) · 856 Bytes
/
Lab4(a)Q5.cpp
File metadata and controls
44 lines (43 loc) · 856 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
using namespace std;
void customized_comb_sort(float *product_prices,int n){
float shrink=2.2;
int gap=n;
bool swapped=true;
while(gap>1||swapped){
gap=(int)(gap/shrink);
if(gap<1){
gap=1;
}
swapped=0;
for(int i=0;i+gap<n;i++){
if(product_prices[i]>product_prices[i+gap]){
float temp=product_prices[i];
product_prices[i]=product_prices[i+gap];
product_prices[i+gap]=temp;
swapped=true;
}
}
}
}
void display(float *arr,int n){
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
int main(){
int n;
cout<<"ENTER SIZE:";
cin>>n;
float product_price[n];
cout<<"ENTER PRICES:"<<endl;
for(int i=0;i<n;i++){
cin>>product_price[i];
}
cout<<"ORIGINAL LIST:"<<endl;
display(product_price,n);
cout<<"SORTED LIST:"<<endl;
customized_comb_sort(product_price,n);
display(product_price,n);
}