-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy patharray_adt.cpp
More file actions
49 lines (45 loc) · 959 Bytes
/
Copy patharray_adt.cpp
File metadata and controls
49 lines (45 loc) · 959 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
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define O cout<<
#define I cin>>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define speed_karo ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
struct Array{
int A[10];
int size;
int length;
};
void display(struct Array a){
for(int i=0;i<a.length;i++){
cout<<a.A[i]<<" ";
}
}
void append(struct Array *a,int x){
if((a->length) < (a->size)){
a->A[a->length++]=x;
}
}
void insert(struct Array *a,int x,int index){
int i;
if( index>=0 && index<=a->length){
for(i=a->length;i>index;i--){
a->A[i]=a->A[i-1];
}
a->A[index]=x;
a->length++;
}
}
int main(){
struct Array a={{8,7,9,5,1,2},10,6};
// a.size =10;
// a.length =5;
// a.A = (int*)malloc(5*(sizeof(int)));
// append(&a,10);
insert(&a,3,4);
display(a);
return 0;
}