0% found this document useful (0 votes)
25 views6 pages

Practical DSUC

Uploaded by

rkumargupta205
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)
25 views6 pages

Practical DSUC

Uploaded by

rkumargupta205
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/ 6

Q.NO1. Write a program to insert an element in an array.

// Inser on in Array...

#include<stdio.h>

void display(int arr[],int n){

for(int i=0;i<n;i++)

prin ("%d\t",arr[i]);

prin ("\n");

void arrInser on(int arr[], int size, int element, int index){

for(int i=size-1;i>=index;i--)

arr[i+1]=arr[i];

arr[index]=element;

int main(){

int arr[100] = {7, 8, 12, 27, 88};

int size=5;

int element=6;

int index=1;

arrInser on(arr,size,element,index);

size=size+1;

display(arr,size);

}
Q.NO2. Write a program to delete an element from an array.

// Dele on in Array...

#include<stdio.h>

void display(int arr[],int n){

for(int i=0;i<n;i++)

prin ("%d\t",arr[i]);

prin ("\n");

void arrInser on(int arr[], int size, int index){

for(int i=index;i<size;i++)

arr[i]=arr[i+1];

int main(){

int arr[100] = {7, 8, 12, 27, 88};

int size=5;

int index=2;

arrInser on(arr,size,index);

size=size-1;

display(arr,size);

}
Q.NO3. Write a program to implement stack using array.

// Stack Opera on(Push and Pop) using in Array

#include <stdio.h>

int stack[100],i,j,choice=0,n,top=-1;

void push();

void pop();

void show();

void main ()

prin ("Enter the number of elements in the stack ");

scanf("%d",&n);

prin ("Stack opera ons using array");

prin ("\n----------------------------------------------\n");

while(choice != 4)

prin ("Chose one from the below op ons...\n");

prin ("\n1.Push\n2.Pop\n3.Show\n4.Exit");

prin ("\n Enter your choice \n");

scanf("%d",&choice);

switch(choice)

case 1:

push();

break;

case 2:
{

pop();

break;

case 3:

show();

break;

case 4:

prin ("Exi ng....");

break;

default:

prin ("Please Enter valid choice ");

};

void push ()

int val;

if (top == n )

prin ("\n Overflow");

else

prin ("Enter the value?");

scanf("%d",&val);
top = top +1;

stack[top] = val;

void pop ()

if(top == -1)

prin ("Underflow");

else

top = top -1;

void show()

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

prin ("%d\n",stack[i]);

if(top == -1)

prin ("Stack is empty");

You might also like