Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Baitap5;
- Uses crt;
- Type
- contro=^truong;
- truong=record
- data:string[20];
- Next,Prev :contro;
- end;
- Var
- Pdau,Pcuoi:contro;
- chose : char;
- Procedure tao_ds;
- Var
- dkien:STRING;
- P,R:contro;
- Begin
- clrscr;
- Pdau :=nil;
- Repeat
- writeln('Bo trong du lieu de thoat.');
- write('nhap vao du lieu ');
- readln(dkien);
- if (dkien <> '') then
- begin
- new(p);
- p^.data:=dkien;
- if Pdau=nil then
- begin
- P^.Next :=nil;
- P^.Prev :=nil;
- Pdau:=P;
- Pcuoi:=P;
- end
- else
- begin
- R:=Pcuoi;
- R^.Next:=P;
- P^.Next :=nil;
- P^.prev :=R;
- Pcuoi:=P;
- end;
- END;
- Until dkien='';
- end;
- Procedure inds;
- Var P: contro;
- Begin
- clrscr;
- if Pdau =nil then
- write ('khong co du lieu de in ra')
- else
- begin
- writeln('Danh sach du lieu duoc in ra theo chieu thuan');
- P:=Pdau;
- writeln;
- write('Pdau--',#16);
- Repeat
- write(P^.data:4);
- P:=P^.Next;
- write(' --',#16);
- Until P=nil;
- writeln('Nil');
- writeln;
- P:=Pdau;
- write('Nil',#17,'--');
- Repeat
- write(p^.data:4,' ');
- P:=P^.Next;
- write(#17,'--');
- until P=nil;
- write('Pcuoi');
- End;
- readln;
- End;
- Procedure bo_sungds;
- Var
- data1 :string;
- P,Q,R: contro;
- kt:boolean ;
- Begin
- clrscr;
- write ('nhap du lieu cua con tro Q ');
- readln(data1); P:=Pdau;
- kt:=false;
- repeat
- if data1 =P^.data then
- begin
- kt:=true;
- new(Q);
- write('nhap vao du lieu bo sung');
- readln(Q^.data);
- if P=Pdau then
- begin
- Pdau:=Q;
- Q^.Next:=P;
- P^.Prev:=Q;
- end
- else
- begin
- R:=P^.Prev;
- Q^.Next:=R^.next;
- R^.next:=Q;
- Q^.Prev:=P^.Prev;
- P^.prev:=Q;
- end;
- end;
- P:=P^.Next;
- until P=nil;
- writeln('**************ket thuc bo sung ************');
- if kt=false then write('khong tim thay du lieu vua nhap');
- readln;
- end;
- Begin
- Repeat
- CLRSCR;
- writeln;
- writeln('***TUY CHON CHUC NANG ***');
- writeln('1 nhap vao danh sach');
- writeln('2 in ra danh sach theu chieu thuan ');
- writeln('3 bo sung danh sach ');
- writeln('4 save and exit ');
- writeln('Chuc nang ban chon: ');
- readln(chose);
- case chose of '1':tao_ds;
- '2':inds;
- '3':bo_sungds;
- end;
- until chose ='4';
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement