-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem1_057.cpp
More file actions
67 lines (61 loc) · 1.01 KB
/
Copy pathproblem1_057.cpp
File metadata and controls
67 lines (61 loc) · 1.01 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
using namespace std;
void insertionSort(int arr[], int n)
{
int i, mini, j;
for (i = 1; i < n; i++)
{
mini = arr[i];
j = i - 1;
while (j >= 0 && arr[j] > mini)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = mini;
}
}
int median(int a[], int p)
{
int i;
int l;
int k=(p-1)/2;
cout<<"median: "<<a[k]<<endl;
for(l=k; l<p; l++)
{
a[l]=a[l+1];
}
p--;
return p;
}
int main()
{
int i=0, j, k, l,p=1;
int a[1000];
int mini;
int num;
cout<<"Input Number: "<<endl;
while(true)
{
cin>>num;
if(num==0)
{
return 0;
}
else if(num==-1)
{
if(i==0)
{
cout<<"Invalid";
return 0;
}
insertionSort(a,i);
i=median(a,i);
}
else if(num>0)
{
a[i]=num;
i++;
}
}
}