forked from sethupathib/data_structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alternatives.cpp
58 lines (48 loc) · 839 Bytes
/
alternatives.cpp
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
//#include <bits/stdc++.h>
#include <iostream>
// #include<algorithm>
using namespace std;
void rearrange(int *arr,int l)
{
//Write code here, make changes in the same array
int pos[100],neg[100],k=0,m=0,n=0;
//
for (int i=0;i<l;i++)
{
if(arr[i]>0)
pos[i]=arr[i];
}
for(int i =0;i<l;i++)
{
if(arr[i]<0)
{
neg[k]= arr[i];
k++;
}
}
sort (pos,pos + l/2);
sort(neg,neg+ l/2, greater<int>());
for(int i=0;i<l;i+=2)
{
arr[i]=pos[m];
m++;
}
for(int i=1;i<l;i+=2)
{
arr[i]=neg[n];
n++;
}
for(int i=0;i<l;i++)
{
cout<<arr[i];
}
// for(int i=0;i<l/2;i++)
// {
// cout<<pos[i];
// }
// cout<<"\t\t"<<endl;
// for(int i=0;i<l/2;i++)
// {
// cout<<neg[i];
// }
}