Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program ListProj;
- const MYSTERIOUS_NUMBER = 57978;
- // Ðта конÑтанта вводитÑÑ Ð´Ð»Ñ Ð²Ð¾Ð·Ð¼Ð¾Ð¶Ð½Ð¾Ñти Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð² ÑпиÑок полноправного чиÑла 0
- var
- count, userCount, elementIndex : byte;
- list : array[0..5] of integer;
- element, elementOld, i, ii, iii : integer;
- answer : string;
- wasFound : boolean;
- function isAMysteriousNumber(number : integer) : boolean;
- begin
- if (number = MYSTERIOUS_NUMBER) then
- begin
- isAMysteriousNumber := true;
- end else
- begin
- isAMysteriousNumber := false;
- end;
- end;
- function thereIsAPlaceOnTheRightBefore(index : integer) : boolean;
- var
- cycleVar : integer;
- begin
- for cycleVar := index to 5 do
- begin
- if (list[cycleVar] = MYSTERIOUS_NUMBER) then
- begin
- thereIsAPlaceOnTheRightBefore := true;
- break;
- end;
- if (cycleVar = 5) then
- begin
- thereIsAPlaceOnTheRightBefore := false;
- break;
- end;
- end;
- end;
- function Push(element, elementIndex : integer) : integer;
- begin
- if (count <= 5) then
- begin
- List[elementIndex] := element;
- count += 1;
- end else
- begin
- if (count > 5) then
- writeln;
- writeln('!!!!!!!!!!ERROR: the List is overloaded!!!!!!!!!!');
- writeln;
- end;
- end;
- function Pop(elementIndex : integer) : integer;
- begin
- if (count > 0) then
- begin
- if (List[elementIndex] <> 0) then
- begin
- List[elementIndex] := MYSTERIOUS_NUMBER;
- count -= 1;
- end else
- begin
- writeln;
- writeln('!!!!!!!!!!ERROR: Element index is empty!!!!!!!!!!');
- end;
- end else
- begin
- writeln;
- writeln('!!!!!!!!!!ERROR: List is empty!!!!!!!!!!');
- writeln;
- end;
- end;
- procedure PushBefore();
- var
- endOfCycle : boolean;
- j : integer;
- begin
- write('Enter the element BEFORE which you want to add a new element: ');
- readln(elementOld);
- write('Enter the new element: ');
- readln(element);
- wasFound := false;
- if (count > 0) then
- begin
- for i := 0 to 5 do
- begin
- if (list[i] = elementOld) then
- begin
- if thereIsAPlaceOnTheRightBefore(i - 1) then
- begin
- if (list[i - 1] = MYSTERIOUS_NUMBER) then
- begin
- list[i - 1] := element;
- count += 1;
- end else
- begin
- repeat
- for ii := 1 to 5 do // 0 7 6 4 0 0
- begin
- if (list[i + ii] = MYSTERIOUS_NUMBER) then
- begin
- list[i + ii] := list[i + ii - 1];
- list[i + ii - 1] := MYSTERIOUS_NUMBER;
- if list[i] = MYSTERIOUS_NUMBER then
- begin
- list[i] := element;
- count += 1;
- endOfCycle := true;
- break;
- end;
- break;
- end;
- end;
- until endOfCycle;
- end;
- end else
- begin
- writeln;
- writeln('!!!!!!!!!!ERROR: The element ', list[i], ' is the first element!!!!!!!!!!');
- writeln;
- end;
- wasFound := true;
- break;
- end;
- end;
- if (not wasFound) then
- begin
- writeln();
- writeln('!!!!!!!!!!ERROR: The element ', elementOld, ' was not founded!!!!!!!!!!');
- writeln();
- end;
- end else
- begin
- writeln('!!!!!!!!!!ERROR: List is empty!!!!!!!!!!');
- end;
- end;
- procedure PushAfter();
- var
- endOfCycle : boolean;
- begin
- write('Enter the element AFTER which you want to add a new element: ');
- readln(elementOld);
- write('Enter the new element: ');
- readln(element);
- wasFound := false;
- if (count > 0) then
- begin
- for i := 0 to 5 do
- begin
- if (list[i] = elementOld) then
- begin
- if thereIsAPlaceOnTheRightBefore(i) then
- begin
- if (list[i + 1] = MYSTERIOUS_NUMBER) then
- begin
- writeln('i');
- list[i + 1] := element;
- count += 1;
- end else
- begin
- repeat
- for ii := 1 to 5 do // 0 7 6 4 3 0
- begin
- if (list[i + 1 + ii] = MYSTERIOUS_NUMBER) then
- begin
- list[i + 1 + ii] := list[i + 1 + ii - 1];
- list[i + 1 + ii - 1] := MYSTERIOUS_NUMBER;
- if list[i + 1] = MYSTERIOUS_NUMBER then
- begin
- list[i + 1] := element;
- count += 1;
- endOfCycle := true;
- break;
- end;
- end;
- end;
- until endOfCycle;
- end;
- end else
- begin
- writeln;
- writeln('!!!!!!!!!!ERROR: The element ', list[i], ' is the last element or list is overloaded!!!!!!!!!!');
- writeln;
- end;
- wasFound := true;
- break;
- end;
- end;
- if (not wasFound) then
- begin
- writeln();
- writeln('!!!!!!!!!!ERROR: The element ', elementOld, ' was not founded!!!!!!!!!!');
- writeln();
- end;
- end else
- begin
- writeln('!!!!!!!!!!ERROR: List is empty!!!!!!!!!!');
- end;
- end;
- begin
- count := 0;
- for i := 0 to 5 do list[i] := MYSTERIOUS_NUMBER;
- repeat
- begin
- write('Current List: [ ');
- for i := 0 to 5 do if isAMysteriousNumber(list[i]) then write(' - ') else write(' ', list[i], ' ');
- writeln(']');
- writeln('1. Add element to List');
- writeln('2. Remove element from List');
- writeln('3. Add element before...');
- writeln('4. Add element after...');
- writeln('5. Close the programm');
- readln(answer);
- writeln();
- case answer of
- '1':
- begin
- write('Enter element index to add(first element index = 0): ');
- readln(elementIndex);
- write('Enter element: ');
- readln(element);
- if ((0 <= elementIndex) AND (elementIndex <= 5)) then Push(element, elementIndex) else writeln('error :0');
- end;
- '2':
- begin
- write('Enter element index to remove(first element index = 0): ');
- readln(elementIndex);
- if ((-1 < elementIndex) AND (elementIndex < 6)) then
- begin
- write('Removing element from List - ');
- if (List[elementIndex] = MYSTERIOUS_NUMBER) then
- begin
- writeln('NaN');
- end else writeln(List[elementIndex]);
- Pop(elementIndex);
- end else
- begin
- writeln;
- writeln('element index must be from 0 to 5!');
- end;
- end;
- '3': PushBefore();
- '4': PushAfter();
- end;
- end
- until answer = ('5');
- end.
Advertisement
Add Comment
Please, Sign In to add comment