listtest.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. PROGRAM test;
  2. {
  3. A small test of linklist unit.
  4. [email protected]
  5. }
  6. uses
  7. {$ifdef Amiga}
  8. exec,
  9. {$endif}
  10. linklist, strings;
  11. VAR
  12. Mylist : pList;
  13. MyNode : pFPCNode;
  14. i : Longint;
  15. temp : Longint;
  16. buffer : PChar;
  17. bufsize : Longint;
  18. templist : pList;
  19. BEGIN
  20. CreateList(Mylist);
  21. AddNewNode(Mylist,'Monday');
  22. AddNewNode(Mylist,'Tuesday');
  23. AddNewNode(Mylist,'Wednesday');
  24. AddNewNode(Mylist,'Thursday');
  25. AddNewNode(Mylist,'Friday');
  26. AddNewNode(Mylist,'Saterday');
  27. AddNewNode(Mylist,'Sunday');
  28. writeln;
  29. WriteLN('This is the list');
  30. PrintList(Mylist);
  31. writeln;
  32. WriteLN('Now we are going to remove the last node');
  33. WriteLN('>> Press return');
  34. readln;
  35. RemoveLastNode(Mylist);
  36. PrintList(Mylist);
  37. writeln;
  38. WriteLN('>> Press return to get the size of the list');
  39. writeln;
  40. readln;
  41. WriteLN('The size of allocated list is ', SizeOfList(Mylist));
  42. writeln;
  43. writeln('Now we are going to print all strings' +#10+ 'in the list with the internal commands');
  44. WriteLN('>> Press return');
  45. readln;
  46. i := NodesInList(Mylist);
  47. MyNode := GetFirstNode(Mylist);
  48. FOR temp := 1 TO i DO BEGIN
  49. WriteLN(MyNode^.ln_Name);
  50. MyNode := GetNextNode(MyNode);
  51. END;
  52. writeln;
  53. WriteLN('We will move the last node to the top');
  54. WriteLN('>> Press return');
  55. readln;
  56. MyNode := GetLastNode(Mylist);
  57. MoveNodeTop(Mylist,MyNode);
  58. PrintList(Mylist);
  59. writeln;
  60. WriteLN('We shall change the value in one node');
  61. WriteLN('>> Press return');
  62. readln;
  63. MyNode := GetFirstNode(Mylist);
  64. MyNode := GetNextNode(MyNode);
  65. UpDateNode(MyNode,'This is the new day');
  66. PrintList(Mylist);
  67. writeln;
  68. MyNode := GetNextNode(MyNode);
  69. WriteLN('Now we delete one node');
  70. WriteLN('>> Press return');
  71. readln;
  72. WriteLN('This node is going to be deleted ',GetNodeData(MyNode));
  73. DeleteNode(MyNode);
  74. PrintList(Mylist);
  75. writeln;
  76. WriteLN('Sort the list');
  77. WriteLN('>> Press return');
  78. readln;
  79. SortList(Mylist);
  80. PrintList(Mylist);
  81. writeln;
  82. writeln('Search for a node, in this case Friday');
  83. WriteLN('>> Press return');
  84. readln;
  85. MyNode := FindNodeData(Mylist,'Friday');
  86. IF MyNode <> NIL THEN BEGIN
  87. WriteLN('found the node ',MyNode^.ln_Name);
  88. { or writeln('found the node ',GetNodeData(MyNode)); }
  89. END ELSE BEGIN
  90. WriteLN('Node not found');
  91. END;
  92. writeln;
  93. WriteLN('And now copy the list to a stringbuffer' +#10+ 'and print it');
  94. WriteLN('>> Press return');
  95. readln;
  96. bufsize := SizeOfList(Mylist);
  97. buffer := StrAlloc(bufsize);
  98. ListToBuffer(Mylist,buffer);
  99. WriteLN(buffer);
  100. writeln;
  101. WriteLN('Now we try to copy the list to a new list');
  102. WriteLN('>> Press return');
  103. readln;
  104. templist := CopyList(Mylist);
  105. IF templist <> NIL THEN BEGIN
  106. WriteLN('That went well, the new list is here');
  107. PrintList(templist);
  108. DestroyList(templist);
  109. END ELSE BEGIN
  110. WriteLN('no copy of list');
  111. END;
  112. writeln;
  113. WriteLN('Press return to destroy the list');
  114. readln;
  115. DestroyList(Mylist);
  116. writeln;
  117. WriteLN('All done');
  118. END.