Advertisement
melnikovmaxim

KLENINA_flipping recursion list

Dec 16th, 2019
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.34 KB | None | 0 0
  1. //link https://yadi.sk/d/e8qvlRFIqqruxw
  2. type
  3.    liste = record
  4.      next: ^liste;
  5.      inf: integer;
  6.    end;
  7.  
  8.    list = record
  9.       list1, list2, list3, list4: ^liste;
  10.    end;
  11.  
  12. var
  13.    listw: list;
  14.    i, n1, n2: integer;
  15.  
  16.  
  17.  
  18. procedure vvod(var listw: list; inf: integer);
  19. begin
  20.    begin
  21.       New(listw.list2^.next);
  22.       listw.list2^.inf := inf;
  23.       listw.list2 := listw.list2^.next;
  24.    end;
  25. end;
  26.  
  27.  
  28.  
  29. procedure perev(listw: list; n3: integer);
  30. var
  31.    n4: integer;
  32. begin
  33.    if n3 = n1 then
  34.       writeln('Перевернутый список:');
  35.    begin
  36.       begin
  37.          for n4 := 1 to n3 do
  38.             listw.list1 := listw.list1^.next;
  39.          if listw.list1^.next <> nil then
  40.             Writeln(listw.list1^.inf);
  41.          listw.list1 := listw.list1^.next;
  42.          listw.list1 := listw.list4;
  43.       end;
  44.    end;
  45.    if n3 > 0 then
  46.       perev(listw, n3 - 1);
  47. end;
  48.  
  49. begin
  50.    New(listw.list1);
  51.    listw.list2 := listw.list1;
  52.    New(listw.list3);
  53.    listw.list3 := listw.list1;
  54.    New(listw.list3);
  55.    listw.list4 := listw.list1;
  56.  
  57.  
  58.    writeln('Введите количество элементов списка');
  59.    readln(n1);
  60.    for n2 := 1 to n1 do
  61.       begin
  62.          writeln('Введите элемент (цифры)');
  63.          readln(i);
  64.          vvod(listw, i);
  65.       end;
  66.  
  67.  
  68.       perev(listw, n1);
  69. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement