SHARE
TWEET

Queue(address)

ruzal99 Dec 16th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program project1;
  2. Uses crt;
  3. type
  4.   pQueueitem=^TQueueitem;
  5.   TQueueitem=record
  6.     info:integer;
  7.     next:pQueueitem;
  8.   end;
  9.   var
  10.  pFirst,pLast:pQueueitem;
  11.     a:integer;
  12.     znach:integer;
  13. pTemp: pQueueitem;
  14. Procedure addnew;
  15. begin
  16. writeln('Add the new element to Queue');
  17. if pLast=nil then
  18. begin
  19. New(pLast);
  20. readln(pLast^.info);
  21. pLast^.next:=nil;
  22. pFirst:=pLast;
  23. end
  24. else
  25. begin
  26. New(pTemp);
  27. readln(pTemp^.info);
  28. pTemp^.next:=nil;
  29. pLast^.next:=pTemp;
  30. pLast:=pTemp;
  31. end;
  32. end;
  33. procedure del;
  34. begin
  35. if pTemp<>nil then
  36.   begin
  37.  pTemp:=pFirst;
  38. pFirst:=pFirst^.next;
  39. if pFirst=nil then pLast:=nil;
  40.  Dispose(pTemp);
  41.  
  42.  end;
  43.   end;
  44. procedure output;
  45. var pTemp: pQueueitem;
  46. begin
  47. pTemp:=pFirst;
  48.   if pFirst=nil then
  49.   begin
  50.    writeln;
  51.    writeln('----Queue is empty----');
  52.    exit;
  53.    writeln;
  54.    end;
  55.     writeln('Content of Queue:');
  56.   pTemp:=pFirst;
  57.   while pTemp<>nil do
  58. begin
  59.   write(pTemp^.info,' ');
  60.   pTemp:=pTemp^.next;
  61.   end;
  62.   end;
  63.  
  64. begin
  65.   pFirst:=nil;pLast:=nil;
  66.     repeat
  67.   writeln;
  68.   write('                              Content of Queue: ');
  69.   pTemp:=pFirst;
  70.   while pTemp<>nil do
  71. begin
  72.   write(pTemp^.info,' ');
  73.   pTemp:=pTemp^.next;
  74.   end;
  75.   writeln('-------MENU---------') ;
  76.   writeln('1-Add new element');
  77.   writeln('2-Delete from Queue');
  78.   writeln('3-Output the Queue');
  79.   writeln('4-exit');
  80.   readln(a);
  81.   case a of
  82.     1:addnew;
  83.     2:begin
  84.  del;
  85.  end;
  86.     3:output;
  87.     end;
  88.  
  89.  until a=4 ;
  90. 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