C LAB‎ > ‎(Sem2) Data Structures‎ > ‎

### Q3. WAP to search (linear), insert and delete (at position) an element in an array.

posted Jan 5, 2011, 10:46 AM by Neil Mathew   [ updated Mar 15, 2011, 1:41 AM ]

SOURCE CODE:

 ```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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 ``` ```#include   int Lsearch(int *a, int n, int item) { int i; for(i=0; ipos; i--) a[i]=a[i-1];   a[pos]=item; *n=*n+1; }   void Del(int *a, int *n, int pos) { int i; for(i=pos; i<(*n)-1; i++) a[i]=a[i+1];   *n=*n-1; }   main() { int a[50],n,i; int item,pos;   printf("Enter size of your array: "); scanf("%d",&n);   printf("Enter elements of your array: "); for(i=0; i

OUTPUT:

```Enter size of your array: 5
Enter elements of your array: 2 4 6 8 10

Enter the choice:
1. Search for an element.
2. Insert an element.
3. Delete an element.
4. Display all elements.
0. EXIT

Enter the item to insert: 7

Enter the position to insert element: 4

Enter the choice:
1. Search for an element.
2. Insert an element.
3. Delete an element.
4. Display all elements.
0. EXIT

Elements:  2  4  6  7  8  10

Enter the choice:
1. Search for an element.
2. Insert an element.
3. Delete an element.
4. Display all elements.
0. EXIT

Enter the position of element to delete: 5

Enter the choice:
1. Search for an element.
2. Insert an element.
3. Delete an element.
4. Display all elements.
0. EXIT

Elements:  2  4  6  7  10

Enter the choice:
1. Search for an element.
2. Insert an element.
3. Delete an element.
4. Display all elements.
0. EXIT

Enter the item to search for: 7
Element Found at 4

Enter the choice:
1. Search for an element.
2. Insert an element.
3. Delete an element.
4. Display all elements.
0. EXIT