Uploaded by wreckingrishi11

array list implementation

advertisement
#include<stdio.h>
#define MAX_SIZE 50
int arr[MAX_SIZE];
int size = 0;
void create(){
int i;
printf("enter number of values");
scanf("%d", &size);
printf("enter values");
for(i=0;i<size;i++){
scanf("%d",&(arr[i]));
}
}
void display(){
int i;
for(i=0;i<size;i++)
printf("%d\t",arr[i]);
}
void insert(int pos , int val){
int i;
for(i=size-1;i>=pos;i--){
arr[i+1]=arr[i];
}
arr[pos]=val;
size++;
}
void Delete(int pos){
int i;
for(i=pos;i<size;i++){
arr[i]=arr[i+1];
}
size--;
}
void search(int val){
int i;
for(i=0;i<size;i++){
if(arr[i]==val){
printf("value %d is in position of %d",val,i);
}
}
}
int main(){
int choice,val,pos;
while(1){
printf("\n -------- List Menu -----------\n");
printf("1.create list \n");
printf("2.Insert \n");
printf("3.Delete \n");
printf("4.Display\n");
printf("5.Search\n");
printf("6.Exit\n");
printf("\n--------------------------------------\n");
printf("Enter your choice:\t");
scanf("%d",&choice);
switch(choice){
case 1:
create();
break;
case 2:
printf("enter the position ");
scanf("%d", &pos);
printf("Enter the value" );
scanf("%d", &val);
insert(pos,val);
case 3:
printf("enter the position ");
scanf("%d", &pos);
Delete(pos);
case 4:
display();
break;
case 5:
printf("enter value to search");
scanf("%d", &val);
search(val);
case 6: exit(0);
}
}
}
Download