Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program lab1_3;
- {$APPTYPE CONSOLE}
- {$R *.res}
- Uses
- System.SysUtils;
- Type
- Data = Record
- Name: String[100];
- Number: String[7];
- End;
- Type
- PNote = ^TPhone;
- TPhone = Record
- Val: Data;
- Next: PNote;
- End;
- Procedure CreateNote(Var Note: PNote; Var First: PNote);
- Var
- IsCorrect, DoBreak: Boolean;
- Begin
- New(Note);
- First := Note;
- DoBreak := False;
- IsCorrect := True;
- Writeln('Заполните телефонную книжку. ФИО не более 100 символов, номер = 7 цифрам. Для завершения записи нажмите enter.');
- While DoBreak = False Do
- Begin
- Write('Введите ФИО абонента: ');
- New(Note^.Next);
- Note := Note^.Next;
- Readln(Note^.Val.Name);
- If Note^.Val.Name = '' Then
- Break;
- Write('Введите номер абонента: ');
- Repeat
- Readln(Note^.Val.Number);
- Until IsCorrect;
- End;
- Note^.Next := Nil;
- Write('Конец записи.');
- End;
- Procedure PrintNote(Var Note: PNote; Var First: PNote);
- Begin
- Note := First;
- While Note <> Nil Do
- Begin
- Write(Note^.Val.Name, ' ');
- Writeln(Note^.Val.Number);
- Note := Note^.Next;
- End;
- End;
- Procedure MakeSort(Var Note: PNote; Var First: PNote);
- Var
- Current: PNote;
- Temp: Data;
- WasSorted: Boolean;
- Begin
- WasSorted := True;
- While WasSorted = True Do
- Begin
- WasSorted := False;
- Current := First;
- While Assigned(Current^.Next) Do
- Begin
- If Current^.Val.Name > Current^.Next^.Val.Name Then
- Begin
- Temp := Current^.Val;
- Current^.Val := Current^.Next^.Val;
- Current^.Next^.Val := Temp;
- WasSorted := True;
- End;
- Current := Current^.Next;
- End;
- End;
- End;
- Function Find(Var Note: PNote; Var First: PNote): String;
- Var
- Value: Char;
- SomeName, SomeTelephone: String;
- IsCorrect: Boolean;
- Counter: Integer;
- Begin
- IsCorrect := True;
- Counter := 0;
- Writeln;
- Writeln('Поиск.');
- Writeln('Введите 0, если хотите найти фамилию, введите 1, если хотите найти номер телефона.');
- Repeat
- Readln(Value);
- If Value = '0' Then
- Begin
- Writeln('Введите неабходимую фамилию: ');
- Readln(SomeName);
- Note := First;
- While Note <> Nil Do
- Begin
- If Note^.Val.Name = SomeName Then
- Begin
- Write(Note^.Val.Name, ' ');
- Writeln(Note^.Val.Number);
- Inc(Counter);
- End;
- Note := Note^.Next;
- End;
- If Counter = 0 Then
- Write('Ничего не найдено.')
- Else
- Write('Конец поиска.');
- End
- Else If Value = '1' Then
- Begin
- Writeln('Введите неабходимый номер: ');
- Readln(SomeTelephone);
- Note := First;
- While Note <> Nil Do
- Begin
- If Note^.Val.Number = SomeTelephone Then
- Begin
- Write(Note^.Val.Name, ' ');
- Writeln(Note^.Val.Number);
- Inc(Counter);
- End;
- Note := Note^.Next;
- End;
- If Counter = 0 Then
- Write('Ничего не найдено.')
- Else
- Write('Конец поиска.');
- End
- Else
- Begin
- IsCorrect := False;
- Writeln('Некорректное значение. Повторите ввод.');
- End;
- Until IsCorrect;
- End;
- Var
- First, Note: PNote;
- Begin
- CreateNote(Note, First);
- MakeSort(Note, First);
- PrintNote(Note, First);
- Find(Note, First);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement