forked from jitendrav4u/HacktoberFest22
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray.cpp
87 lines (77 loc) · 1.64 KB
/
array.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <ctime>
#include <unistd.h>
using namespace std;
void print_array(int n, int arr[]){
for (int i = 0; i < n; i++)
{
cout<<arr[i]<<" ";
}
}
int* array_rotation(int arr_size, int arr[], int rotate_by){
int d = rotate_by;
int n = arr_size;
int temp[d];
for(int i = 0; i<d; i++){
temp[i] = arr[i];
}
for(int i=0; i<n-d; i++){
arr[i] = arr[i+d];
}
for(int i=n-d; i<n; i++){
arr[i] = temp[i-n+d];
}
return arr;
}
int* array_reverse(int start, int end, int arr[]){
int temp;
while(start < end){
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
return arr;
}
bool binarySearch(int n, int arr[], int s){
int left, right, mid;
left = 0;
right = n-1;
while(left <= right){
mid = (left + right) / 2;
if(arr[mid] > s){
right = mid-1;
}
else if(arr[mid] < s){
left = mid+1;
}
else if(arr[mid] == s){
cout<<"yes";
return true;
}
}
return false;
}
int spiral_order_print(int m, int n, int *arr){
int row_start = 0, row_end = n-1, column_start = 0, column_end = n-1;
while(row_start < row_end && column_start < column_end){
}
}
int main()
{
cout<<"hi"<<endl;aVB I[1]
int n;
cout<<"Enter n: ";
cin>>n;
int arr[n];
for(int i = 0; i<n; i++){
cin>>arr[i];
}
array_rotation(n, arr, 4);
print_array(n, arr);
// cout<<endl;
// bool p = binarySearch(n, arr, 5);
// cout<<p;
return 0;
}