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

UT code

The document contains two C programs: one for displaying the reverse of a string using a stack and another for performing insert operations on a linear queue using an array. The first program includes functions for pushing and popping characters onto a stack, while the second program manages queue operations like enqueue and display. Both programs utilize basic control structures and standard input/output functions.

Uploaded by

tanmayambi88
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

UT code

The document contains two C programs: one for displaying the reverse of a string using a stack and another for performing insert operations on a linear queue using an array. The first program includes functions for pushing and popping characters onto a stack, while the second program manages queue operations like enqueue and display. Both programs utilize basic control structures and standard input/output functions.

Uploaded by

tanmayambi88
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

'C' program to display reverse of printf("%c",stack[top--]);

string using stack.


}

#include<stdio.h>
void main()
#include<conio.h>
{
#include<string.h>
char str[]="Data_structure";

int len=strlen(str);
int top,stack[20],max=20;
int i;;

clrscr();
void push(char x)

{
for(i=0;i<len;i++)
if(top==max-1)
{
{
push(str[i]);
printf("stack overflow");
}
}
for(i=top;i>=0;i--)
else
{
{
pop();
top++;
}
stack[top]=x;
getch();
}
}
}

void pop()

{
'C' Program to perform INSERT }
Operations on Linear Queue using an
else
Array.
{ r=r+1;

q[r]=val;
#include<stdio.h>
printf("\n Enqueued %d in the
#include<conio.h>
queue \n",val);
#define n 3

int q[n];
}
int f=-1;
}
int r=-1;
void display()
int val;
{

int i;
void Enqueue(int val)
if(r==-1)
{
{
if(r==n-1)
printf("\n Queue is empty");
{
}
printf("Queue overflow \n");
else
return;
{
}
int i;
else if(f==-1 && r==-1)
printf("\n queue elements are:\n");
{
for(i=f;i<=r;i++)
f=r=0;
{
q[r]=val;
printf("%d\t",q[i]);
} case 2:

} display();

} break;

void main()

{ case 3:

int choice,val; printf("exiting...\n");

clrscr(); break;

do

{ default:

printf("\n 1:enqueue \n \n printf("invalid");


2:display \n 3.exit \n");
}
printf(" Enter your choice=");
}
scanf("%d",&choice);
while(choice!=3);

getch();
switch(choice)
}
{

case 1:

printf("Enter element to
insert=");

scanf("%d",&val);

Enqueue(val);

break;

You might also like