Write any data structure program (stack implementation)



Write any data structure program (stack implementation) ..

Answer / chauhan rakesh botad

#include<stdio.h>

int main()
{
int a[100], i;
printf("To pop enter -1\n");
for(i = 0;;)
{
printf("Push ");
scanf("%d", &a[i]);
if(a[i] == -1)
{
if(i == 0)
{
printf("Underflow\n");
}
else
{
printf("pop = %d\n", a[--i]);
}
}
else
{
i++;
}
}
}
{
programmer : clx321
file : stack.pas
unit : Pstack.tpu
}
program TestStack;
{this program uses ADT of Stack, I will assume that the unit
of ADT of Stack has already existed}

uses
PStack; {ADT of STACK}

{dictionary}
const
mark = '.';

var
data : stack;
f : text;
cc : char;
ccInt, cc1, cc2 : integer;

{functions}
IsOperand (cc : char) : boolean; {JUST Prototype}
{return TRUE if cc is operand}
ChrToInt (cc : char) : integer; {JUST Prototype}
{change char to integer}
Operator (cc1, cc2 : integer) : integer; {JUST Prototype}
{operate two operands}

{algorithms}
begin
assign (f, cc);
reset (f);
read (f, cc); {first elmt}
if (cc = mark) then
begin
writeln ('empty archives !');
end
else
begin
repeat
if (IsOperand (cc)) then
begin
ccInt := ChrToInt (cc);
push (ccInt, data);
end
else
begin
pop (cc1, data);
pop (cc2, data);
push (data, Operator (cc2, cc1));
end;
read (f, cc); {next elmt}
until (cc = mark);
end;
close (f);
end
}

Is This Answer Correct ?    6 Yes 4 No

Post New Answer

More C Interview Questions

code snippet for creating a pyramids triangle ex 1 2 2 3 3 3

4 Answers  


Explain what is the benefit of using an enum rather than a #define constant?

0 Answers  


What will be the output of the following program #include<stdio.h> void main() { int i=20; i-=i+++++i++; printf("%d",i); }

5 Answers  


Array is an lvalue or not?

0 Answers  


Explain how can I prevent another program from modifying part of a file that I am modifying?

0 Answers  






Is flag a keyword in c?

0 Answers  


What will be your course of action for a push operation?

0 Answers  


How many parameters should a function have?

0 Answers  


How to avoid structure padding in C?

8 Answers   Tech Mahindra,


How are 16- and 32-bit numbers stored?

0 Answers  


can u write a program in C, which does not use = (eqaul)or any arithmatic assignment(like -=,+=,*= etc) operator to swap to number?

2 Answers  


How can I manipulate individual bits?

0 Answers  


Categories