forked from shikharkohli/c---files
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnms.cpp
More file actions
executable file
·55 lines (42 loc) · 676 Bytes
/
nms.cpp
File metadata and controls
executable file
·55 lines (42 loc) · 676 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
45
46
47
48
49
50
51
52
53
54
55
//Non monotonic subsequence incomplete
#include<iostream>
#include<stdio.h>
using namespace std;
int nextlowest(int arr[100],int len,int n)
{
for(int i=n;i<len;i++)
{
if(arr[i+1]<arr[i])
n++;
else
return n;
}
return n;
}
int nexthighest(int arr[100],int len,int n)
{
for(int i=n;i<len;i++)
{
if(arr[i+1]>arr[i])
n++;
else
return n;
}
return n;
}
int main()
{
int arr[20]={2,3,4,1,6,7,3,4,9,8,1,2,6,7,4,5,3};int len=17;
cout<<arr[0]<<" ";
for(int i=0;i<len;i++)
{
if(i%2==1)
i=nextlowest(arr,len,i);
else
i=nexthighest(arr,len,i);
cout<<arr[i]<<" ";char ch;
// getchar();
}
cout<<endl;
return 0;
}