0% found this document useful (0 votes)
12 views15 pages

Data Structure

Uploaded by

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

Data Structure

Uploaded by

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

PRACTICAL 1

Traversing : Traversing means accessing each element of Array exactly once.

PROGRAM TO TRAVERSE THE ARRAY ELEMENTS:

#include<stdio.h>

#include<conio.h>

void main()

int n,k;

int LA[100];

clrscr();

printf("\n Enter total number of elements in array");

scanf("%d",&n);

printf("\n Enter the elements in array");

for(k=0;k<=n-1;k++)

scanf("%d",&LA[k]);

printf("\n The elements of array are ");

for(k=0;k<=n-1;k++)

printf("\n %d",LA[k]);

getch();
}

OUTPUT:

PRACTICAL 2

INSERTION: Adding a new element in already existing array is called insertion.

PROGRAM TO INSERT NEW ELEMENT IN ALREADY EXISTING ARRAY:

#include<stdio.h>

#include<conio.h>

void main()

int n,k,j,i,ITEM;

int LA[5];

clrscr();

printf("\n Enter total number number of elements in an array ");

scanf("%d",&n);

printf("\n Enter the elements in an array");


for(i=0;i<=n-1;i++)

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

printf("\n Enter the element you want to insert ");

scanf("%d",&ITEM);

j=n-1;

while(j>=k)

LA[j+1]=LA[j];

j=j-1;

LA[k]=ITEM;

n=n+1;

printf("\n Array after insertion is ");

for(i=0;i<=n-1;i++)

printf("\n %d",LA[i]);

getch();

OUTPUT:
PRACTICAL 3

DELETION: Removing an element from an array is called as deletion.

PROGRAM TO REMOVE AN ELEMENT FROM THE ARRAY:

#include<stdio.h>

#include<conio.h>

void main()

int i,N,J,K,ITEM;

int LA[100];

clrscr();

printf("\n Enter the total number of elements in an array");

scanf("%d",&N);

printf("\n Enter the elements in an array");

for(i=0;i<=N-1;i++)
{

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

printf("\n Enter the element youn want to delete ");

scanf("%d",&ITEM);

printf("\n Enter the location of element you want to delete ");

scanf("%d",&K);

ITEM=LA[K];

for(J=K;J<=N-1;J++)

LA[J]=LA[J+1];

N=N-1;

printf("\n Array after deletion is");

for(i=0;i<=N-1;i++)

printf("\n %d",LA[i]);

getch();

OUTPUT:
PRACTICAL 4

LINEAR SEARCH: Linear search also called as sequential search is an approach


to find out the element from the linear list of array. If the elements in the array
are unsorted than linear search is perform.

PROGRAM:

#include<stdio.h>

#include<conio.h>

void main()

int N,K,LOC,ITEM,i;

int LA[100];

clrscr();

printf("\n Enter total nnumber of elements in an array");

scanf("%d",&N);

printf("\n Enter the elements in an array");


for (i=0;i<=N-1;i++)

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

printf("\n Enter the element you want to search ");

scanf("%d",&ITEM);

K=0,LOC=-1;

while(K<=N-1)

if(LA[K]==ITEM)

LOC=K;

break;

else

K=K+1;

if(LOC==-1)

printf("\n Item is not in the array");

else

{
printf("\n Item is present in the array at location %d",LOC);

getch();

OUTPUT:

PRACTICAL 5

BINARY SEARCH: The Binary search can be applied to the sorted array of
elements. Binary Search method is fast as compare to Linear search. In Binary
search the array list is divided into two equal parts.

PROGRAM:

#include<stdio.h>

#include<conio.h>

void main()

int BEG,END,MID,ITEM,N,INT,i;

int LA[100];

clrscr();

printf("\n Enter the total number of elements in an array");


scanf("%d",&N);

printf("\n Enter the elements in an array");

for(i=0;i<=N-1;i++)

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

printf("\n Enter the element you want to search");

scanf("%d",&ITEM);

BEG=0,END=N-1,MID=(BEG+END)/2;

while(BEG<=END&& LA[MID]!=ITEM)

if(ITEM<LA[MID])

END=MID-1;

else

BEG=MID+1;

MID=(BEG+END)/2;

if(LA[MID]==ITEM)

{
printf("\n Item is present at location %d",MID);

else

printf("\n Item is not present in the list");

getch();

OUTPUT:

PRACTICAL 6

PUSH: It is the term used to insert an element into a Stack.

PROGRAM:

#include<stdio.h>

#include<conio.h>

void main()

int MAXSTK=100,TOP=-1,ITEM,i,N;
int STACK[100];

clrscr();

printf("\n Enter the total number of elements in stack");

scanf("%d",&N);

printf("\n Enter the elements in stack");

for(i=0;i<=N-1;i++)

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

TOP=TOP+1;

printf("\n Enter the element you want to push in stack");

scanf("%d", &ITEM);

if(TOP==MAXSTK)

printf("OVERFLOW");

else

TOP=TOP+1;

STACK[TOP]=ITEM;

N=N+1;

for(i=0;i<=N-1;i++)
{

printf("\n %d",STACK[i]);

getch();

OUTPUT:

PRACTICAL 7

POP: It is the term used to delete an element from a stack.

PROGRAM:

BUBBLE SORT : It is the technique used to sort the elements of an array in


ascending order or descending order .

PROGRAM:

#include<stdio.h>
#include<conio.h>

void main()

int N,K,PTR,i;

int LA[100];

clrscr();

printf("\n Enter the total number of elements ");

scanf("%d",&N);

printf("\n Enter the elements in an array");

for(i=0;i<=N-1;i++)

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

for(K=1;K<=N-1;K++)

PTR=0;

while(PTR<=N-K)

if(LA[PTR]>LA[PTR+1])

int temp;

temp=LA[PTR];

LA[PTR]=LA[PTR+1];
LA[PTR+1]=temp;

else

PTR=PTR+1;

printf("\n Array after insertion is");

for(i=0;i<=N-1;i++)

printf("\n %d",LA[i]);

getch();

OUTPUT:

You might also like