Advertisement
mrlolthe1st

Untitled

Aug 12th, 2021
1,783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.15 KB | None | 0 0
  1. Const
  2.     MaxSize = 1024;
  3. Type
  4.     TListType = LongInt;
  5.     TList = Record
  6.         Size : Word;
  7.         Nodes : Array [0 .. MaxSize] Of TListType;
  8.     End;
  9.     PListType = ^TListType;
  10.  
  11. Var
  12.     A : TList;
  13.  
  14. Procedure InitList(Var List : TList);
  15. Begin
  16.     List.Size := 0;
  17. End;
  18.  
  19. Procedure AppendElement(Var List : TList; Element : TListType);
  20. Begin
  21.     List.Nodes[List.Size] := Element;
  22.     Inc(List.Size);
  23. End;
  24.  
  25. Function PopElement(Var List : TList) : PListType;
  26. Begin
  27.     Dec(List.Size);
  28.     PopElement := Addr(List.Nodes[List.Size]);
  29. End;
  30.  
  31. Procedure RemoveAt(Var List : TList; Pos : Word);
  32. Begin
  33.     Dec(List.Size);
  34.     For Pos := Pos To List.Size - 1 Do
  35.         List.Nodes[Pos] := List.Nodes[Pos + 1];
  36. End;
  37. Procedure PrintList(Var List : TList);
  38. Var
  39.     I : LongInt;
  40. Begin
  41.     WriteLn('List size: ', List.Size);
  42.     For I := 0 To LongInt(List.Size) - 1 Do
  43.         Write(List.Nodes[I], ' ');
  44.     WriteLn;
  45. End;
  46.  
  47. Begin
  48.     InitList(A);
  49.     AppendElement(A, 1);
  50.     AppendElement(A, 2);
  51.     AppendElement(A, 3);
  52.     AppendElement(A, 4);
  53.     PrintList(A);
  54.     WriteLn(PopElement(A)^);
  55.     RemoveAt(A, 1);
  56.     PrintList(A);
  57. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement