Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Napraviti stack sa 4 broja

[es] :: Pascal / Delphi / Kylix :: Napraviti stack sa 4 broja

[ Pregleda: 1931 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

query
NL

Član broj: 51311
Poruke: 30
*.upc-j.chello.nl.



Profil

icon Napraviti stack sa 4 broja26.04.2005. u 16:50 - pre 231 meseci
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.
 
Odgovor na temu

_v!rus_
BGD

Član broj: 40451
Poruke: 313
*.nat-pool.bgd.sbb.co.yu.



+1 Profil

icon Re: Napraviti stack sa 4 broja27.04.2005. u 20:06 - pre 231 meseci
[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;

 
Odgovor na temu

query
NL

Član broj: 51311
Poruke: 30
*.upc-j.chello.nl.



Profil

icon Re: Napraviti stack sa 4 broja29.04.2005. u 17:33 - pre 231 meseci
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.
 
Odgovor na temu

query
NL

Član broj: 51311
Poruke: 30
*.upc-j.chello.nl.



Profil

icon Re: Napraviti stack sa 4 broja01.05.2005. u 15:12 - pre 231 meseci
Rijeseno. ;)
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: Napraviti stack sa 4 broja

[ Pregleda: 1931 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.