Допиши программу, чтобы можно было добавить и убрать элемент из очереди с выводом этой…
- User
Допиши программу, чтобы можно было добавить и убрать элемент из очереди с выводом этой очереди Program obsch;
type TypeNode = ^Node; Node = record a: integer; Next: TypeNode; end;
procedure cleanQ(var first, last: TypeNode); begin first := nil; last := nil; end;
function emptyQ(var first, last: TypeNode):boolean; begin if (first = nil) and (last = nil) then emptyQ := true else emptyQ := false; end;
procedure addQ(var first, last: TypeNode; e: TEO); var pcurr: TypeNode; begin new(pcurr); pcurr^.a := e; pcurr^.next := nil; last^.next := pcurr; end;
function deleteQ(var first, last:TypeNode): boolean; var pcurr: TypeNode; begin if(first = nil) and (last = nil) then begin deleteQ := false; end else if (first = last) and (last <> nil) then begin pcurr := first; first := nil; last := nil; dispose(pcurr); deleteQ := true end else begin pcurr := first; first := first^.next; dispose(pcurr); deleteQ := true; end; end;
- Assistant
procedure printQ(first: TypeNode); var p: TypeNode; begin p := first; while p <> nil do begin writeln(p^.a); p := p^.next; end; end;
var first, last: TypeNode; e: integer; choice: integer;
begin cleanQ(first, last);
repeat writeln('1. Add element to queue'); writeln('2. Delete element from queue'); writeln('3. Print queue'); writeln('4. Exit'); write('Enter your choice: '); readln(choice);
case choice of 1: begin write('Enter element to add: '); readln(e); if (first = nil) and (last = nil) then begin new(first); first^.a := e; first^.next := nil; last := first; end else addQ(first, last, e); end; 2: begin if not deleteQ(first, last) then writeln('Queue is empty'); end; 3: begin if emptyQ(first, last) then writeln('Queue is empty') else printQ(first); end; 4: begin writeln('Exiting program...'); end; else writeln('Invalid choice'); end; writeln;until choice = 4; end.
- User
Допиши программу с возможностью добавления и удаления пользователем элементов стека, а также выводом стека Program obsch;
type T = integer; TypeNode = ^Node; Node = record a: T; Next: TypeNode; end;
var top: TypeNode; x: T;
procedure vstav (var L: TypeNode); begin L := nil; end;
function emptyS(top: TypeNode): boolean; begin if (top = nil) then emptyS := true else emptyS := false; end;
procedure addS(var Top: TypeNode; x: T; pcurr: TypeNode); begin new(pcurr); pcurr^.a := x; pcurr^.next := top; top := pcurr; end;
function deleteS(var top: TypeNode): boolean; var pcurr: TypeNode; begin if (top = nil) then deleteS := false else if (top^.next = nil) then begin pcurr := top; top := nil; dispose(pcurr); deleteS := true; end else begin pcurr := top; top := top^.next; dispose(pcurr); deleteS := true; end; end;
- Assistant
procedure printS(top: TypeNode); var p: TypeNode; begin p := top; while p <> nil do begin writeln(p^.a); p := p^.next; end; end;
var choice: integer; pcurr: TypeNode;
begin vstav(top);
repeat writeln('1. Add element to stack'); writeln('2. Delete element from stack'); writeln('3. Print stack'); writeln('4. Exit'); write('Enter your choice: '); readln(choice);
case choice of 1: begin write('Enter element to add: '); readln(x); addS(top, x, pcurr); end; 2: begin if not deleteS(top) then writeln('Stack is empty'); end; 3: begin if emptyS(top) then writeln('Stack is empty') else printS(top); end; 4: begin writeln('Exiting program...'); end; else writeln('Invalid choice'); end; writeln;until choice = 4; end.
- User
Исправь эту программу: Program obsch;
type TypeNode = ^node; node = record s:char; next:TypeNode; end;
var inn, ou: string; i, j: integer; c: char; top: TypeNode;
function deleteS(var top: TypeNode; x: char): boolean; var pcurr: TypeNode; begin if (top = nil) then deleteS := false else if (top^.next = nil) then begin pcurr := top; top := nil; dispose(pcurr); deleteS := true; end else begin pcurr := top; top := top^.next; dispose(pcurr); deleteS := true; end; end;
procedure addS(var Top: TypeNode; x: char); var pcurr: TypeNode; begin new(pcurr); pcurr^.s := x; pcurr^.next := top; top := pcurr; end;
begin j := 1; addS(Top, '('); read(inn); for i := 1 to length(inn) do begin if(inn[i] >= '0') and (inn[i] <= '9') then ou[j] := inn[i]; j += 1; end; if (inn[i] = '(') then addS(top, '('); if(inn[i] = ')') then begin deleteS(top, c); while(c <> '(') do begin deleteS(top, c); if(c = '+') or (c = '-') or (c = '*') or (c = '/') then begin ou[j] := c; j += 1; end; end;
if (c = '*') or (c = '/') then while(c <> '(') do begin deleteS(top, c); ou[j] := c; j += 1; end;
if (c = '+') or (c = '-') then while (c <> '*') and (c <> '/') and (c <> '(') do begin deleteS(top, c); ou[j] := c; j += 1; end; end; deleteS(top, c); while(c <> '(') do begin ou[j] := c; j += 1; deleteS(top, c); end; write(ou); end.
- Assistant
Program obsch;
type TypeNode = ^Node; Node = record s: char; next: TypeNode; end;
var inn, ou: string; i, j: integer; c: char; top: TypeNode;
function deleteS(var top: TypeNode; var x: char): boolean; var pcurr: TypeNode; begin if (top = nil) then deleteS := false else if (top^.next = nil) then begin x := top^.s; pcurr := top; top := nil; dispose(pcurr); deleteS := true; end else begin x := top^.s; pcurr := top; top := top^.next; dispose(pcurr); deleteS := true; end; end;
- User
Проверь на наличие ошибок
- Assistant
К сожалению, вашего кода нет. Пожалуйста, опубликуйте свой код, чтобы я мог проверить его на наличие ошибок.
- User
Проверь свой код
- Assistant
У меня нет кода для проверки. Пожалуйста, опубликуйте свой код, чтобы я мог его проверить.
- User
Program obsch;
type TypeNode = ^Node; Node = record s: char; next: TypeNode; end;
var inn, ou: string; i, j: integer; c: char; top: TypeNode;
function deleteS(var top: TypeNode; var x: char): boolean; var pcurr: TypeNode; begin if (top = nil) then deleteS := false else if (top^.next = nil) then begin x := top^.s; pcurr := top; top := nil; dispose(pcurr); deleteS := true; end else begin x := top^.s; pcurr := top; top := top^.next; dispose(pcurr); deleteS := true; end; end;
procedure addS(var Top: TypeNode; x: char); var pcurr: TypeNode; begin new(pcurr); pcurr^.s := x; pcurr^.next := top; top := pcurr; end;
begin j := 1; addS(Top, ‘(’); read(inn); for i := 1 to length(inn) do begin if (inn[i] >= ‘0’) and (inn[i] <= ‘9’) then ou[j] := inn[i] else if (inn[i] = ‘(’) then addS(top, ‘(’) else if (inn[i] = ‘)’) then begin deleteS(top, c); while (c <> ‘(’) do begin deleteS(top, c); if (c = ‘+’) or (c = ‘-’) or (c = ‘') or (c = ‘/’) then begin j += 1; ou[j] := ’ '; j += 1; ou[j] := c; end else begin j += 1; ou[j] := ’ '; j += 1; ou[j] := c; end; end; end else if (inn[i] = ‘+’) or (inn[i] = ‘-’) then begin deleteS(top, c); while (c <> ‘(’) and (c <> '’) and (c <> ‘/’) do begin j += 1; ou[j] := ’ '; j += 1; ou[j] := c; deleteS(top, c); end; addS(top, c); addS(top, inn[i]); end else if (inn[i] = ‘') or (inn[i] = ‘/’) then begin deleteS(top, c); while (c = '’) or (c = ‘/’) do begin j += 1; ou[j] := ’ '; j += 1; ou[j] := c; deleteS(top, c); end; addS(top, c); addS(top, inn[i]); end; j += 1; end;
- Assistant
В коде есть ошибки:
- Кавычки должны быть обычными, а не кавычками-лапками, т.к. некоторые символы (например, знак деления) заключены в одинарные кавычки:
addS(Top, '('); ... addS(top, '(') ... while (c = '*') or (c = '/') do- Символ умножения заключен в одинарные кавычки вместо двойных:
if (c = '+') or (c = '-') or (c = '’’) or (c = '/') then ... else if (inn[i] = '’’) or (inn[i] = '/') then
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.