Contoh Program Stack Pascal

01.01.2020by admin
Contoh Program Stack Pascal 7,9/10 8171 reviews

Source Code:uses crt;typeTStack = recordStacks: array0.10 of integer;top: integer;end;vartumpukan: TStack;// menginisialisasikan stackfunction initStack(var stack:TStack): boolean;beginstack.top:= -1; // kondisi stack kosonginitStack:= true;end;function push(var stack:TStack; data: integer): boolean;beginif high(stack.stacks) = stack.top then beginwriteln('Ups.! Tumpukan penuh');push:= false;exit;endelse begininc(stack.top);stack.stacksstack.top:= data;push:= true;end;end;function pop(var stack: TStack): integer;beginif stack.top = -1 then beginwriteln('Ups.! Tumpukan telah kosong');pop:= -1end else beginpop:= stack.stacksstack.top;stack.stacksstack.top:=0;dec(stack.top);end;end;var jawab, data: byte;beginclrscr;initStack(tumpukan);repeatwriteln('1.

Contoh Program Pascal Stack

Masukan data kedalam tumpukan ');writeln('2. Keluarkan data dari tumpukan ');writeln('0. Keluar ');write('Masukan pilihan anda:'); readln(jawab);case jawab of1: beginwrite('Masukan datanya:'); readln(data);push(tumpukan, data);end;2: beginwriteln('Data Tumpukan teratas = ', pop(tumpukan));end;0:;else writeln('Maaf!

Salah memasukan tombol');end;readln;until jawab =0;end.

Contoh Program Stack Pascal Software

Infix expression: The expression of the form a op b. When an operator is in-between every pair of operands.Postfix expression: The expression of the form a b op. When an operator is followed for every pair of operands.Postfix notation, also known as reverse Polish notation, is a syntax for mathematical expressions in which the mathematical operator is always placed after the operands. Though postfix expressions are easily and efficiently evaluated by computers, they can be difficult for humans to read. Complex expressions using standard parenthesized infix notation are often more readable than the corresponding postfix expressions. Consequently, we would sometimes like to allow end users to work with infix notation and then convert it to postfix notation for computer processing. Sometimes, moreover, expressions are stored or generated in postfix, and we would like to convert them to infix for the purpose of reading and editingExamples:Input: abcOutput: (a + (b + c))Input: ab.c+Output: ((a.b)+c).

Contoh program stack pascal c

Array Operations Pascal

We have already discussed. Below is algorithm for Postfix to Infix.Algorithm1.While there are input symbol left1.1 Read the next symbol from the input.2.If the symbol is an operand2.1 Push it onto the stack.3.Otherwise,3.1 the symbol is an operator.3.2 Pop the top 2 values from the stack.3.3 Put the operator, with the values as arguments and form a string.3.4 Push the resulted string back to stack.4.If there is only one value in the stack4.1 That value in the stack is the desired infix string.Below is the implementation of above approach.