| (21:57 04/05/02) רימע ודיע .הככ ?המל |
|
unit Queue;
interface
Uses list2;
(*------------------------------------------------*)
Type
Tor = list_type;
(*------------------------------------------------*)
procedure tor_init(var Q : list_type);
(* Initialize s to be an empty queue. *)
function tor_empty( Q : list_type) : boolean;
(* Returns TRUE if queue is empty, FALSE otherwise. *)
procedure tor_push(var Q : list_type; x : list_info_type);
(* Place item x in queue end. *)
tor_pop(var Q : list_type; var x : list_info_type);
procedure item in stack head to x, and remove it from the stack. *)
(* Move the s is not empty *)
(* Assumption:
procedure tor_top( Q : list_type; var x : list_info_type);
item in stack head to x, without changing the stack *)
(* Copy the s is not empty *)
(* Assumption:
implementation
procedure tor_init(var Q : list_type);
begin
list_init(Q);
end;
function tor_empty( Q : list_type) : boolean;
begin
tor_empty:=list_is_empty(Q);
end;
procedure tor_push(var Q : list_type; x : list_info_type);
Var
end_of_line: pos_type;
begin
end_of_line:=list_end(Q);
end_of_line:=list_prev(Q, end_of_line);
list_insert(Q, end_of_line, x);
end;
tor_pop(var Q : list_type; var X : list_info_type);
procedure Var
Y:pos_type;
begin
y:=list_anchor(Q);
y:=list_next(Q, y);
list_retrieve(Q, Y, x);
list_delete(Q, Y);
end;
procedure tor_top( Q :list_type; var x :list_info_type);
Var
y:pos_type;
begin
y:=list_anchor(Q);
y:=list_next(Q, Y);
list_retrieve(Q, Y, x);
end;
begin
(* No initialization needed *)
end.
Program Ex1;
Type
Dept = (Milk, Elec, Meet);
Objects = Record
ObjCode:LongInt;
ObjName:String;
ProviderCode:LongInt;
case ObjDept:Dept of
Milk: (Fat:byte;
Bio:Boolean);
Elec: (Watt:Byte);
Meet: (MeetType:String;
Fresh: Boolean);
End;
Var
ObjData: File of Objects;
Rec: Objects;
Cont:Boolean;
ObjDept: integer;
Continue, BioChk, FreshChk: Char;
Begin
Assign (ObjData, 'ObjData1.dat');
ReWrite (ObjData);
Cont:=True;
While Cont do
Begin
WriteLn ('What is the item code? ' );
Readln ( Rec.ObjCode);
WriteLn (' what is the item name? ' );
ReadLn (Rec.ObjName);
WriteLn (' what is the item provider code? ' );
ReadLn (Rec.ProviderCode);
WriteLn (' which department does the item belong to? ' );
WriteLn (' For milk press 1');
WriteLn (' For electricity press 2' );
WriteLn (' For Meet press 3' );
Readln (ObjDept);
Case ObjDept of
1: Begin
Rec.ObjDept:=Milk;
WriteLn(' How much fat is there on the item? ' );
ReadLn (Rec.fat);
WriteLn(' is it a bio product? Y/N' );
Readln (BioChk);
If ((BioChk='y') or (BioChk='Y')) then
Rec.bio:=True
Else
Rec.bio:=False;
End;
2: Begin
Rec.ObjDept:=Elec;
Writeln (' How much Watt does the product uses? ' );
Readln (Rec.Watt);
End;
3: Begin
Rec.ObjDept:=Meet;
WriteLn (' What is the meet type? ' );
ReadLn (Rec.MeetType);
WriteLn (' Does the product fresh? Y/N' );
ReadLn (FreshChk);
If ((FreshChk='Y') or (FreshChk='y')) then
Rec.Fresh:=True
Else
Rec.Fresh:=False;
End;
End;
WriteLn (' Would you like to continue? ' );
Readln (continue);
If ((Continue='Y') or (Continue='y')) then
Cont:=True
Else
Cont:=False;
Write (ObjData, Rec);
WriteLn;WriteLn;WriteLn;WriteLn;WriteLn;WriteLn;WriteLn;
End;
Close(ObjData);
End.
רשק רוצ העדוה ספדה רבחל חלש הבוגת :תויורשפא |
|
|
|