daily pastebin goal
39%
SHARE
TWEET

LIST(1)(address)

ruzal99 Dec 16th, 2018 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program project1;
  2. type
  3. pListitem=^TListitem;
  4. TListitem=record
  5. info:integer;
  6. next:pListitem;
  7. end;
  8. var pFirst,pTemp,pNew,pLast:pListitem;
  9. k,key,znach,otv:integer;
  10.  
  11. Function search(key:integer):pListitem;
  12. begin
  13. pTemp:=pFirst^.next;
  14. while pTemp<>nil do
  15. begin
  16. if (pTemp^.info=key) then
  17. begin
  18. result:=pTemp;
  19. break;
  20. end
  21. else
  22. begin
  23. pTemp:=pTemp^.next;
  24. result:=nil;
  25. end;
  26. end;
  27. end;
  28. Function search2(key:integer):pListitem;
  29. begin
  30. pTemp:=pFirst^.next;
  31. pLast:=pFirst;
  32. while (pTemp<>nil) do
  33. if (pTemp^.info=key) then
  34. begin
  35. result:=pLast;
  36. break;
  37. end
  38. else
  39. begin
  40. pTemp:=pTemp^.next;
  41. pLast:=pLast^.next;
  42. result:=nil;
  43. end;
  44. end;
  45.  
  46. Procedure AddAfter;
  47. begin
  48. if pFirst^.next=nil then
  49. begin
  50. writeln('Enter the first element:');
  51. readln(znach);
  52. pTemp:=pFirst;
  53. New(pNew);
  54. pNew^.info:=znach;
  55. pNew^.next:=pTemp^.next;
  56. pTemp^.next:=pNew;
  57. end
  58. else
  59. begin
  60. writeln('Enter the element after which you want to add:');
  61. readln(key);
  62. pTemp:=search(key);
  63. if (pTemp<>nil) then
  64. begin
  65. writeln('Add the element: ');
  66. readln(znach);
  67. New(pNew);
  68. pNew^.info:=znach;
  69. pNew^.next:=pTemp^.next;
  70. pTemp^.next:=pNew;
  71. end
  72. else
  73. writeln('ERROR!!!!Element dont find');
  74. end;
  75. end;
  76. Procedure AddBefore;
  77. begin
  78. if pFirst^.next=nil then
  79. begin
  80. writeln('Enter the first element:');
  81. readln(znach);
  82. pTemp:=pFirst;
  83. New(pNew);
  84. pNew^.info:=znach;
  85. pNew^.next:=pTemp^.next;
  86. pTemp^.next:=pNew;
  87. end
  88. else
  89. begin
  90. writeln('Enter the element before which you want to add:');
  91. readln(key);
  92. pTemp:=search(key);
  93. pLast:=search2(key);
  94. if (pTemp<>nil) then
  95. begin
  96. writeln('Add the element:');
  97. readln(znach);
  98. New(pNew);
  99. pNew^.info:=znach;
  100. pNew^.next:=pTemp;
  101. pLast^.next:=pNew;
  102. end
  103. else
  104. writeln('ERROR!!!!Element dont find');
  105. end;
  106. end;
  107. Procedure DELETE;
  108. begin
  109. if pFirst^.next=nil then
  110. writeln('List Is EMPTY.')
  111. else
  112. begin
  113. writeln('Enter the element which you want delete:');
  114. readln(key);
  115. pTemp:=search(key);
  116. pLast:=search2(key);
  117. if pTemp<>nil then
  118. begin
  119. pLast^.next:=pTemp^.next;
  120. pTemp:=nil;
  121. end
  122. else
  123. writeln('ERROR!!!!Element dont find');
  124. end;
  125. end;
  126. Procedure output;
  127. begin
  128. if pFirst^.next=nil then
  129. writeln('-----List is EMPTY-----')
  130. else
  131. begin
  132. pTemp:=pFirst^.next;
  133. writeln('Content of List:');
  134. while pTemp<>nil do
  135. begin
  136. write(pTemp^.info,' ');
  137. pTemp:=pTemp^.next;
  138. end;
  139. end;
  140. end;
  141. begin
  142. New(pFirst);
  143. pFirst^.next:=nil;
  144. repeat
  145. pTemp:=pFirst^.next;
  146. writeln(' ');
  147. write('                                  Content of List: ');
  148. while pTemp<>nil do
  149. begin
  150. write(pTemp^.info,' ');
  151. pTemp:=pTemp^.next;
  152. end;
  153. writeln;
  154. writeln('-----------MENU----------');
  155. writeln('1-Add the element AFTER');
  156. writeln('2-Add the element BEFORE');
  157. writeln('3-Delete the element');
  158. writeln('4-Output to monitor');
  159. writeln('5-Exit');
  160. writeln;
  161. readln(otv);
  162. case otv of
  163. 1:AddAfter;
  164. 2:AddBefore;
  165. 3:DELETE;
  166. 4:output;
  167. end;
  168. until otv=5;
  169.  
  170. 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