[ query @ 26.04.2005. 16:50 ] @
Program koji treba da napravim glasi:
Een stack napraviti sa 4 broja i onda vrijednosti jednu po jednu iz stack-a ucitati i isprintati.
Ovdje treba da koristim sljedecu proceduru:
Code:


unit untStack;

interface

type
  TStackNodePtr = ^TStackNode;
  TStackNode = record
  iValue: Integer;
  snpNext: TStackNodePtr
end;

procedure Push (iNewValue: Integer);
{ This procedure pushes value iNewValue on the stack.
  When there is no more free memory space, the exception
  EOutOfMemory will be raised.
  pre: -
  post: Value iNewValue on top of stack or exception EOutOfMemory is raised}

function Pop: Integer;
{ This function pops the top-most value from the stack and returns its value.
  pre: Stack is not empty
  post: Pop = former topmost value of stack
  and this value has been removed from the stack }

function IsEmpty: Boolean;
{ This function returns TRUE if and only if the stack is empty.
  pre: -
  post: IsEmpty = TRUE <==> stack is empty}

implementation

var
  snpTop: TStackNodePtr = NIL;

procedure Push (iNewValue: Integer);
var
  snpNewNode: TStackNodePtr;
begin { Push }
  New (snpNewNode); { may raise EOutOfMemory exception }
  snpNewNode^.iValue := iNewValue;
  snpNewNode^.snpNext := snpTop;
  snpTop := snpNewNode
end { Push };

function Pop: Integer;
var
  snpOldNode: TStackNodePtr;
begin { Pop }
  snpOldNode := snpTop;
  snpTop := snpTop^.snpNext;
  result := snpOldNode^.iValue;
  Dispose (snpOldNode)
end { Pop };

function IsEmpty: Boolean;
begin { IsEmpty }
  result := snpTop = NIL
end { IsEmpty };

end.


Dali neko ima neki slican primjer?

Unaprijed hvala.
[ _v!rus_ @ 27.04.2005. 20:06 ] @
[offtopic]
C++ programer? (Hungarian notation, UCase consts...)

Code:

for iTeller1 := 0 to untStack.Pop

Ti izgleda hoces hoces 4 iteracije, a ne onoliko iteracija koliki je posledni push-nuti integer. Takodje nigde nemas Pop..

Znaci...
Code:

for iTeller1 := 0 to 3 do
begin
  ...
  ...
  untStack.Pop;
end;

[ query @ 29.04.2005. 17:33 ] @
Kako mislis off topic i c++ programer?
Meni ovo treba za skolu (predmet je Delphi). Nemam ja zive veze kako stack radi i ostali vazoni, ucim se. ;) Mada mi se zgadio ovaj Delphi moram priznati...

Ima li neko da mi pomogne u vezi ovoga?

Unaprijed hvala.
[ query @ 01.05.2005. 15:12 ] @
Rijeseno. ;)