1d Array
1d Array
Assignment Number:
Problem statement:
Program in c to perform 1: insertion, 2: deletion, 3: Searching, 4: Sorting, 5:
Reverse an array
ALGORITHM:
Input: An array A[10]
Output: The item is found successfully in specific position or suitable unsuccessful massage.
LINEAR SEARCH
STEP 1: SET I TO 1
STEP 4: SET I TO I + 1
STEP 5: GO TO STEP 2
STEP 8: EXIT.
BUBBLE SORTING
STEP 1: SET P=1.
Page No.
Date:
STEP 9: A[J]=A[J+1].
Output: The item is successfully inserted in specific position or suitable unsuccessful massage.
.DISPLAY
STEP 5: END
Output: The item is been deleted successfully from its specific position or suitable unsuccessful massage.
Page No.
Date:
STEP 6: END
REVERSE_ARRAY
STEP 1: SET M=N-1;
STEP 5: END.
Source Code:
#include<stdio.h>
#include<conio.h>
#define SIZE 10
int A[SIZE],n;
int l=0,u=n-1;
int i;
for(i=l;i<=u;i++)
if(A[i]==element)
Page No.
Date:
break;
if(i==u+1)
int p,j,t;
for(p=1;p<n;p++)
for(j=0;j<n-p;j++)
if(A[j]>A[j+1])
t=A[j];
A[j]=A[j+1];
A[j+1]=t;
else
continue;
int index,k;
Page No.
Date:
if(pos_i<1||pos_i>n+1)
printf("\nInvalid position");
else
index=pos_i-1;
for(k=n-1;k>=index;k--)
A[k+1]=A[k];
A[index]=item;
n=n+1;
void display()
int m;
for(m=0;m<=n-1;m++)
printf("%d ",A[m]);
int index,i;
index=pos_d-1;
for(i=index;i<n-1;i++)
A[i]=A[i+1];
n=n-1;
void reverse_array()
Page No.
Date:
int m;
for(m=n-1;m>=0;m--)
printf("%d ",A[m]);
int main()
scanf("%d",&n);
if(n>SIZE-1)
else
for(i=0;i<n;i++)
scanf("%d",&A[i]);
for(i=0;i<n;i++)
printf("%d ",A[i]);
while(1)
scanf("%d",&ch);
switch(ch)
Page No.
Date:
scanf("%d",&item);
scanf("%d",&pos_i);
insert(pos_i,item);
display();
break;
scanf("%d",&pos_d);
del_pos_element(pos_d);
display();
break;
case 3: bubble_sort();
display();
break;
case 4: reverse_array();
break;
scanf("%d",&element);
linear_search(element);
break;
case 6:exit(0);
Page No.
Date:
Output:
34816
3 4 8 1 6
6.Exit
324816
6.Exit
32816
Page No.
Date:
6.Exit
6.Exit
86321
6.Exit
6 is found in 4 position
6.Exit
Page No.
Date:
Discussion:
In array the user have to set the size of the array while compiling the program, but in linked list there is no
need for setting the size.
Page No.