Advertisement
ruzal99

LIST(massive)

Dec 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.11 KB | None | 0 0
  1. program project1;
  2. const q=5;
  3.   var count,otv,i:integer;
  4.   new,old,a,s:integer;
  5.   List:array [0..q] of integer;
  6. procedure AddBefore;
  7.    var a,s,k: byte;
  8. begin
  9. if count> q then writeln('----List is FULL----');
  10. if count=0 then
  11.   begin
  12.     writeln('Add new element');
  13.     readln(List[0]);
  14.     count:=count+1;
  15.     exit;
  16.   end;
  17.    if count>0 then
  18.      begin
  19.   writeln('Enter the element before which you want to paste');
  20.   readln(a);
  21.   writeln('Add new element');
  22.   readln(s);
  23.   for k:=0 to 5 do
  24.   if list[k]=a then begin
  25.     for i:=count downto k do
  26.     list[i+1]:=list[i];
  27.     list[k]:=s;
  28.     count:=count+1;
  29.     exit;
  30.   end;
  31.   end;
  32.  end;
  33.  procedure Addafter;
  34.    var a,s,k: byte;
  35. begin
  36.   if count> q then writeln('----List is FULL----');
  37. if count=0 then
  38.   begin
  39.     readln(List[0]);
  40.     count:=count+1;
  41.     exit;
  42.   end;
  43.    if count>0 then
  44.      begin
  45.    writeln('Enter the element after which you want to paste');
  46.    readln(a);
  47.    writeln('Add new element');
  48.   readln(s);
  49.   for k:=0 to 5 do
  50.   if List[k]=a then begin
  51.     for i:=count-1 downto k do
  52.    List[i+1]:=List[i];
  53.     List[k+1]:=s;
  54.     count:=count+1;
  55. end;
  56.   end;
  57.    end;
  58.   procedure Delete;
  59.    var a,s,k: byte;
  60.    i:integer;
  61. begin
  62. if count=0 then begin writeln ('List is empty');
  63.   exit;
  64.     end;
  65. if count>0 then
  66.   begin
  67. writeln('Enter the element which you want delete:');
  68.  readln(a);
  69.   for k:=0 to 5 do
  70.   if list[k]=a then begin
  71.     for i:=k to count do
  72.     list[i]:=list[i+1];
  73.     exit;
  74.     end;
  75.    end;
  76. end;
  77.    procedure output;
  78.    begin
  79.      writeln('Content of list:');
  80.      for i:=0 to 5 do
  81.       write (List[i], ' ');
  82.      writeln;
  83.     end;
  84. begin
  85.   repeat
  86.     write('                       Content of list:');
  87.      for i:=0 to 5 do
  88.       write (List[i], ' ');
  89.      writeln;
  90.  writeln('-------MENU--------- ');
  91.  writeln('1-Add the element BEFORE');
  92.  writeln('2-Add the element AFTER');
  93.  writeln('3-Delete the element');
  94.  writeln('4-Output to monitor:');
  95.  writeln('5-Exit:');
  96.  readln(otv);
  97.  case otv of
  98.  1: begin
  99.  
  100.  AddBefore;
  101.  end;
  102.  
  103.  2: AddAfter;
  104.  3: Delete;
  105.  4: output;
  106.  end;
  107.  until otv=5;
  108. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement