Professional Documents
Culture Documents
arrADT Assig1
arrADT Assig1
2023
Reg No: 3122225001033
UCS 2312 Data Structures Lab
Assignment 1: Array ADT and its application
Create an ADT for the array data structure with the following functions. arrADT will have the
integer array and size.
a. create(arrADT,size, array) – Create the array with the required number of elements
b. deleteAt(arrADT, pos ) – Delete the specified element
c. insertAtEvery(arrADT,data) – Insert data before every element
d. search(arrADT, key) – return the position of the second occurrence of the element. If found
return the position, otherwise return 1
e. printArray(arrADT) – prints the elements of the array
f. findPeek(arrADT, int *) – return a set of peek elements
Source code:
Header file:
#include<stdio.h>
#include<stdlib.h>
struct arrAdt {
int* array;
int size;
};
}
void display(struct arrAdt* newa) {
for (int i = 0;i < newa->size;i++){
printf("%d ", newa->array[i]);}
printf("\n");
}
}
}
else{
if(newa->array[i]>newa->array[i+1] && newa->array[i]>newa-
>array[i-1]){
arr1[j]=newa->array[i];
j++;
}
}
}
for (int k=0;k<j;k++){
printf("%d\t",arr1[k]);
}
}
Main file:
#include"arrAdt.h"
int main()
{
struct arrAdt newarray;
int choise;
int a=1;
while(a!=0){
printf("\n1-create a new array\n2-deleting\n3-searching\n4-finding
peak\n5-inserting at every position\n");
printf("enter the choice:");
scanf("%d",&choise);
switch(choise)
{
case 1:
printf("creating the array:\n");
printf("enter the number of elements:");
int size;
scanf("%d",&size);
create(&newarray,size);
display(&newarray);
break;
case 2:
printf("deleting:\n");
printf("enter the position of the element to delete:");
int pos;
scanf("%d",&pos);
deleteAt(&newarray,pos);
display(&newarray);
break;
case 3:
printf("searching:\n");
int key,res;
case 4:
printf("finding peak:\n");
peak(&newarray);
break;
case 5:
printf("inserting at every position\n");
int ins;
printf("enter the number to insert:");
scanf("%d",&ins);
insertAtEvery(&newarray,ins);
display(&newarray);
a=0;
break;
}
}}
Sample Output: