0% found this document useful (0 votes)
10 views

Implementation of Array List Operations

The document implements various array list operations like insertion, deletion and searching on an integer array. It includes functions to insert and delete elements from the beginning, end or a specified position of the array. Other functions can display, search and count the elements in the array.

Uploaded by

slalitha.613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Implementation of Array List Operations

The document implements various array list operations like insertion, deletion and searching on an integer array. It includes functions to insert and delete elements from the beginning, end or a specified position of the array. Other functions can display, search and count the elements in the array.

Uploaded by

slalitha.613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

/* Implementation of array list operations */

#include<stdio.h>

#include<stdlib.h>

void create(int a[]);

void insert_pos(int a[],int,int);

void insert_begin(int a[],int);

void insert_end(int a[],int);

void delete_begin(int a[]);

void delete_pos(int a[],int);

void delete_end(int a[]);

void search(int a[],int);

void count(int a[]);

void display(int a[]);

int size;

int main()

int a[100];

int choice,pos,ele;

create(a);

do

printf("1.insert_begin\n");
printf("2.insert_pos\n");

printf("3.insert_end\n");

printf("4.delete_begin\n");

printf("5.delete_pos\n");

printf("6.delete_end\n");

printf("7.display\n");

printf("8.search\n");

printf("9.total count\n");

printf("10.exit\n");

printf("Enter your choice\n");

scanf("%d",&choice);

switch(choice)

case 1:

printf("enter new element to insert at begin\n");

scanf("%d",&ele);

insert_begin(a,ele);

break;

case 2:

printf("enter new element to insert\n");

scanf("%d",&ele);

printf("enter the position to insert new element\n");


scanf("%d",&pos);

insert_pos(a,pos,ele);

break;

case 3:

printf("enter new element to insert at end\n");

scanf("%d",&ele);

insert_end(a,ele);

break;

case 4:

delete_begin(a);

break;

case 5:

printf("enter the position of element to be deleted\n");

scanf("%d",&pos);

delete_pos(a,pos);

break;

case 6:

delete_end(a);

break;

case 7:

display(a);

break;

case 8:

printf("enter element to be searched\n");


scanf("%d",&ele);

search(a,ele);

break;

case 9: count(a);

break;

case 10: exit(1);

default: printf("invalid choice\n");

}while(choice<=10);

return 0;

} //End of main

void create(int a[])

int i;

printf("enter the size\n");

scanf("%d",&size);

printf("enter array elements\n");

for(i=0;i<size;i++)

scanf("%d",&a[i]);

}//End of creation
void insert_end(int a[],int ele)

a[size] = ele;

size++;

}//End of insert at end

void insert_begin(int a[],int ele)

int i;

//logic begins here

for(i=size ;i>0 ; i--)

a[i] = a[i-1];

a[0] = ele;

size++;

}//End of insert at begin

void insert_pos(int a[],int pos,int ele)

int i;

if(pos<0 || pos>size)

{
printf("insertion not possible,invalid position\n");

return;

for(i=size; i>pos; i--)

a[i]=a[i-1];

a[pos]=ele;

size++;

} //End of insert at position

void delete_begin(int a[])

int i,ele;

ele = a[0];

for(i=0;i<size;i++)

a[i] = a[i+1];

size--;

printf("Deleted element is %d\n",ele);


} //End of delete at begin

void delete_end(int a[])

int ele;

ele = a[size-1];

size--;

printf("Deleted element is %d\n",ele);

}//End of delete at end

void delete_pos(int a[],int pos)

int i,ele;

ele = a[pos];

if(pos<0 || pos>=size)

printf("deletion not possible,invalid position\n");

return;

for(i=pos;i<size;i++)

a[i] = a[i+1];

}
size--;

printf("Deleted element is %d\n",ele);

} //End of delete at position

void display(int a[])

int i;

printf("Elements in array\n");

for(i=0 ; i<size ; i++)

printf("%d\t",a[i]);

}//End of display

void search(int a[],int ele)

int i; //loc to store location of ele initially set to -1

//logic for searching ele in array a

for(i=0;i<size;i++)

if(ele==a[i])

printf("Search successful\n");

printf("Element %d found at %d location\n",a[i],i);

return;
}

printf("Search unsuccessful\n");

} //End of search

void count(int a[])

int i,totalcount=0;

//logic to count number of elements in array

for(i=0;i<size;i++)

printf("Total elements in array : %d\n",totalcount);

} //End of count

You might also like