SHARE
TWEET

Untitled

a guest Oct 13th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program huh;
  2.  
  3. type
  4.   PNode = ^TNode;
  5.   TNode = record
  6.     value: integer;
  7.     next: PNode;
  8.   end;
  9.  
  10. var
  11.   head: PNode;
  12.   input: string;
  13.   pusharr: array of string;
  14.  
  15. procedure printStack(p: PNode);
  16. begin
  17.   while p <> nil do
  18.   begin
  19.     write(p^.value);
  20.     write(' -> ');
  21.     p := p^.next;
  22.   end;
  23.   writeln('nil');
  24. end;
  25.  
  26. procedure push(var p: PNode; val: integer);
  27. var
  28.   newE: PNode;
  29. begin
  30.   new(NewE);
  31.   newE^.value := val;
  32.   newE^.next := p;
  33.   p := newE;
  34.   writeln('ok');
  35. end;
  36.  
  37. function size(p: PNode): integer;
  38. begin
  39.   size := 0;
  40.   while p <> nil do
  41.   begin
  42.     size += 1;
  43.     p := p^.next;
  44.   end;
  45. end;
  46.  
  47. procedure pop(var p: PNode);
  48. var
  49.   temp: PNode;
  50. begin
  51.   if size(p) > 0 then begin
  52.     writeln(p^.value);
  53.     temp := p;
  54.     p := p^.next;
  55.     dispose(temp);
  56.   end else writeln('error');
  57. end;
  58.  
  59. procedure back(p: PNode);
  60. begin
  61.   if size(p) > 0 then writeln(p^.value)
  62.   else writeln('error');
  63. end;
  64.  
  65.  
  66. procedure clear(var p: PNode);
  67. begin
  68.   while p <> nil do
  69.   begin
  70.     p := p^.next;
  71.   end;
  72.   writeln('ok');
  73. end;
  74.  
  75. begin
  76.   head := nil;
  77.  
  78.   while input <> 'exit' do
  79.   begin
  80.     readln(input);
  81.     case input of
  82.       'back':
  83.         back(head);
  84.       'size':
  85.         writeln(size(head));
  86.       'exit':
  87.         writeln('bye');
  88.       'clear':
  89.         clear(head);
  90.       'pop':
  91.         pop(head);
  92.       else begin
  93.         pusharr := input.Split(' ');
  94.         push(head, pusharr[1].ToInteger);
  95.       end;
  96.     end;
  97.   end;
  98. 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
 
Top