SHARE
TWEET

Untitled

a guest Oct 20th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type PNode = ^Node;
  2.      Node = record
  3.        data: string;
  4.        next: PNode;
  5.      end;
  6. type TextF = text;
  7.  
  8. procedure Push(var Head: PNode; x: string);
  9. var NewNode: PNode;
  10.     begin
  11.     New(NewNode);
  12.     NewNode^.data := x;
  13.     NewNode^.next := Head;
  14.     Head := NewNode;
  15.     end;
  16.  
  17. function Pop(var Head: PNode): string;
  18. var q: PNode;
  19.     begin
  20.     if Head = nil then
  21.         begin
  22.         Pop := char(255);
  23.         Exit;
  24.         end;
  25.     Pop := Head^.data;
  26.     q := Head;
  27.     Head := Head^.next;
  28.     Dispose(q);
  29.     end;
  30.  
  31. function isEmptyStack (S: PNode): Boolean;
  32.     begin
  33.     isEmptyStack := (S = nil);
  34.     end;
  35.  
  36. var stack: PNode;
  37.     buff_s: string;
  38.     f: TextF;
  39.     begin
  40.     assign(f, './6.txt');
  41.     reset(f);
  42.     while not eof(f) do
  43.         begin
  44.         readln(f, buff_s);
  45.         Push(stack, buff_s);
  46.         write(buff_s, ' ');
  47.         end;
  48.     writeln;
  49.     while not isEmptyStack(stack) do
  50.         begin
  51.         write(Pop(stack), ' ');
  52.         end;
  53.     close(f);
  54.     end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top