Write any data structure program (stack implementation)

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?

812


Is c language still used?

541


Write a factorial program using C.

653


What is a newline escape sequence?

672


What is string length in c?

620






What are the types of data structures in c?

606


What is call by value in c?

567


What is the right way to use errno?

628


How can you determine the size of an allocated portion of memory?

748


Declare the structure which contains the following members and write in C list of all students who score more than 75 marks. Roll No, Name, Father Name, Age, City, Marks.

693


Explain what is wrong with this statement? Myname = ?robin?;

1051


What does malloc () calloc () realloc () free () do?

565


using for loop sum 2 number of any 4 digit number in c language

1740


Explain void pointer?

596


Explain what is the difference between a string and an array?

642