PDA

View Full Version : Cấu trúc dữ liệu và giải thuật



caungoc_9x
10-12-2009, 10:07
help me.!!.
huhu, có ai giúp e với. bọn e fải làm bài tập về Cài đặt giải thuật duyệt cây (trước ,sau,giữa). bọn em chỉ fải làm duyệt sau thôi(làm cả 3 thì càng tốt ạ). Pác nào giúp em với k thì e chết mất. e xyn cảm ơn rất rất nhiều !!
Yêu cầu: -ý tưởng giải thuật,ý tưởng chương trình.
-Chạy được chương trình.

technolt
10-12-2009, 16:30
Đại khái như sau

Duyệt giữa


procedure attemp(u:node);
begin
attemp(u.left);
//Process u node
attemp(u.right);
end;


Duyệt trước


procedure attemp(u:node);
begin
//Process u node
attemp(u.left);
attemp(u.right);
end;


Duyệt sau


procedure attemp(u:node);
begin
attemp(u.left);
attemp(u.right);
//Process u node
end;

songohan2009
10-12-2009, 18:11
Cấu trúc này có vẻ giống Binary Search Tree nhỉ? :-?

congkhanhhck
10-12-2009, 18:19
các bạn ơi. trả lời cho mình bài pascal này với, bài toán như sau:hãy sử dụng UNIT MATRAN để nhận vào hai ma trận, rồi tính tổng, tích hai ma trận đó. chuyển vị hai ma trận vào đầu tiên. các bạn gửi vào địa chỉ này cho mình nhé:congkhanhhck@gmail.com, thank các bạn nha

caungoc_9x
11-12-2009, 00:20
cảm ơn các pác nhé!!! nhưg mà không hỉu sao nó lại ko chạy hả pạn ơi??? toàn báo lỗi ở ngay dòng đầu tiên thui

trinhvandung
14-01-2010, 08:24
Các bạn ơi, ai có giải thuật tính giá trị trung bình của cây nhị phân bằng phương pháp đệ qui không post cho mình với, hoặc bạn nào có ý tưởng giải thuật nào không xin chỉ giúp. thanks

keyhaidia
19-01-2010, 17:44
cac anh oi em dang hoc cau truc du lieu va giai thuat pascal em dang can cac dang bai tap co loi giai va de thi de em hoc va chuan bi kiem tra.anh nao co cho em xin voi!

Minh Beo
20-01-2010, 17:50
Gởi Bạn congkhanhhck, nếu đây là bài tập, Bạn phải tự làm. Dưới đây tôi chỉ giúp gợi ý cách làm bằng thư viện
theo phương pháp hướng đối tượng và sử dụng con trỏ cấp phát bộ nhớ động, Bạn nào cần đều có thể sử dụng thư viện này.
Chúc các Bạn thành công.

file TYPEOBJ như sau:

Unit Typeobj;
{Nguoi viet: Duong Quang Minh, SV 87X3 DHBK Da Nang}
Interface
{$R-}
Type
typ = real{double};
onereal = array[1..1] of typ;
onerealptr= ^onereal;
tst = string[50];
tfile = file of typ;
Implementation
{$R+}
END.{ of Unit }


file thư viện vec tơ ma trận như sau:

Unit VeMaobj;
{Nguoi viet: Duong Quang Minh, SV 87X3 DHBK Da Nang}
{$N+,R-,f-}
Interface
Uses typeobj,printer;

Type
Realvector = object
Maxvectorsize,
Vsize :word;
Vecptr :onerealptr;
vectoropstatus:boolean;
Constructor Init(maxelem:word {in});
Destructor Done;
Function currensize:word;
Procedure Store(index:word {in}; x:typ{in});
Procedure Recall(index:word {in};Var x:typ{out});
Procedure Fill(fillvalue:typ {in};numelem:word{in});
Procedure Addscalar(scalar:typ{in});
Procedure Multscalar(scalar:typ{in});
Procedure AddVector(vectB:realvector{in});
Function Multvector(vectB:realvector{in}):typ;
End;
Realmatrix=object
Nrow,Ncol,
Rows,Cols : word;
Matptr : onerealptr;
Deteminant : typ;
Matopstatus: boolean;
Function Loc(row,{in} col:word {in}):word;
Constructor Init(numrow,{in} numcol:word {in});
Destructor Done;
Procedure Querysize(var numrow,{out} numcol:word {out});
Procedure Store(Row,{in} col:word {in}; x:typ{in});
Procedure Recall(Row,{in} col:word {in};Var x:typ{out});
Procedure Fill(fillvalue:typ {in};rowcount{in},colcount:word{in});
Procedure Addscalar(scalar:typ{in});
Procedure Multscalar(scalar:typ{in});

{
Cac phuong thuc duoi day cac ban tu giai quyet nhe

Procedure MultVector(invect:realvector {in};Var outvect:realvector{out}); {nhan voi vec to}
Procedure VectorMult(invect:realvector{in};Var outvect:realvector{out}); {nhan vec to voi ma tran}
Procedure MultMatrix(inmat:realmatrix{in};Var outmat:realmatrix{out}); {nhan voi ma tran inmat}
Procedure Movematrix(Var matb:realmatrix{out}); {chuyen ma tran}
Procedure Readmatrix(numrows{in},numcols{in}:word); {doc ma tran}
Procedure Writematrix(numrows{in},numcols{in}:word); {ghi ma tran}
Procedure Matrix_1;{DK Rows=Cols} {nghich dao}
Procedure Matrix_T(var outmat:realmatrix); {chuyen vi}
procedure Addmatrix(inmat:realmatrix;var outmat:realmatrix); {cong ma tran}
procedure ChinhLK(ro:typ;mat1,t,mat2:realmatrix); {cac phuong thuc con lai dung de giai bai toan ket cau}
procedure ChuyentrucK(t,mat:realmatrix);
procedure StoreAll(inmat:realmatrix);
procedure ChuyentrucF(t,f:realmatrix);
Procedure GiaiHe(mttt:realmatrix{in};
Var mtas:realmatrix{out});
}
End;


Implementation
Uses crt;
Constructor Realvector.Init(maxelem:word {in});
Begin
maxvectorsize:=maxelem;
vsize:=0;
Getmem(vecptr,maxelem*sizeof(typ));
vectoropstatus:=true;
End;
Destructor realvector.done;
var temp : typ;
Begin
temp:=vecptr^[1];
freemem(vecptr,maxvectorsize*sizeof(typ));
vecptr:=Nil;
maxvectorsize:=0;
vsize:=0;
vectoropstatus:=true;
End;
function realvector.currensize:word;
Begin
vectoropstatus:=true;
currensize:=vsize;
End;
Procedure realvector.store(index:word;{in} x:typ {in});
Begin
If index>maxvectorsize then begin
vectoropstatus:=false;
Exit;
End;
vecptr^[index]:=x;
If index>vsize then vsize:=index;
vectoropstatus:=true;
End;
Procedure realvector.recall(index:word{in};Var x:typ{out});
Begin
If index>vsize then begin
vectoropstatus:=false;
x:=0;
Exit;
end;
x:=vecptr^[index];
vectoropstatus:=true;
End;
Procedure realvector.Fill(fillvalue:typ {in};numelem:word{in});
Var i:word;
Begin
If numelem>maxvectorsize then
numelem:=maxvectorsize;
vsize:=numelem;
for i:=1 to numelem do
vecptr^[i]:=fillvalue;
vectoropstatus:=true;
End;
Procedure realvector.addscalar(scalar:typ{in});
Var i:word;
Begin
for i:=1 to vsize do
vecptr^[i]:=vecptr^[i]+scalar;
vectoropstatus:=true;
End;
Procedure realvector.Multscalar(scalar:typ{in});
Var i:word;
Begin
for i:=1 to vsize do
vecptr^[i]:=vecptr^[i]*scalar;
vectoropstatus:=true;
End;
Procedure realvector.addvector(vectB:realvector{in});
Var i:word;
Begin
if vsize<>vectb.vsize then begin
vectoropstatus:=false;
Exit;
end;
for i:=1 to vsize do
vecptr^[i]:=vecptr^[i]+vectB.vecptr^[i];
vectoropstatus:=true;
End;
Function realvector.multvector(vectB:realvector{in}):typ;
Var i:word;
sum:typ;
Begin
If vsize<>vectb.vsize then begin
vectoropstatus:=false;
multvector:=0;
exit;
end;
sum:=0;
for i:=1 to vsize do
sum:=sum+vecptr^[i]*vectB.vecptr^[i];
vectoropstatus:=true;
Multvector:=sum;
End;
Function realmatrix.Loc(row{in},col{in}:word):word;
Begin
Loc:=(row-1)*Ncol+col;
End;
Constructor realmatrix.Init(numrow{in},numcol{in}:word);
Begin
Ncol:=numcol;
Nrow:=numrow;
rows:=0;
cols:=0;
Getmem(matptr,numcol*numrow*sizeof(typ));
matopstatus:=true;
End;
Destructor realmatrix.done;
var temp : typ;
Begin
temp:=matptr^[loc(1,1)];
freemem(matptr,nrow*ncol*sizeof(typ));
matptr:=nil;
rows:=0;
cols:=0;
nrow:=0;
ncol:=0;
temp:=0;
matopstatus:=true;
End;
Procedure realmatrix.querysize(Var numrow{out},numcol{out}:word);
Begin
numrow:=rows;
numcol:=cols;
matopstatus:=true;
End;
Procedure realmatrix.store(row{in},col{in}:word;x:typ{in});
Begin
If (row>nrow) or (col>ncol) then begin
matopstatus:=false;
exit;
end;
If row>rows then
rows:=row;
If col>cols then
cols:=col;
matptr^[loc(row,col)]:=x;
matopstatus:=true;
End;
Procedure realmatrix.recall(row{in},col{in}:word;Var x:typ{out});
var gia:typ;
Begin
If (row>rows) or (col>cols) then begin
matopstatus:=false;
x:=0;
exit;
end;
x:=matptr^[loc(row,col)];
if ((row=nrow) and (col=ncol)) then gia:=matptr^[loc(1,1)];
matopstatus:=true;
End;
Procedure realmatrix.fill(fillvalue:typ{in};rowcount{in},col count{in}:word);
Var i,j:word;
Begin
IF rowcount>nrow then
rowcount:=nrow;
If colcount>ncol then
colcount:=ncol;
rows:=rowcount;
cols:=colcount;
for i:=1 to rowcount do
for j:=1 to colcount do
matptr^[loc(i,j)]:=fillvalue;
matopstatus:=true;
End;
Procedure realmatrix.addscalar(scalar:typ{in});
Var i,j,k:word;
Begin
for i:=1 to rows do
for j:=1 to cols do begin
k:=loc(i,j);
matptr^[k]:=matptr^[k]+scalar;
end;
matopstatus:=true;
End;
Procedure realmatrix.multscalar(scalar:typ{in});
Var i,j,k:word;
Begin
for i:=1 to rows do
for j:=1 to cols do begin
k:=loc(i,j);
matptr^[k]:=matptr^[k]*scalar;
end;
matopstatus:=true;
End;

{$R+,F+}
END.{ of Unit }

tanphi12
03-03-2010, 09:48
cho một mảng a={12,32,45,6,5,767,9}--->a={6,12,32,767,45,9,5}
hãy sắp xếp sao cho số chẵn tăng dần trứoc và số lẽ giảm dần sau.
nếu bạn nào có thể chuyển tất cả số chẵn về đầu mảng và sô lẻ về cuối mảng thì cũng được rồi,
phần còn lại để mình. ví dụ như:
mảng a sau khi sắp xếp a={12,32,6,45,5,767,9}
bạn nào có thể viết được thì post len giúp mình nha!

[=========> Bổ sung bài viết <=========]

số điện thoại của mình là:01223432477 hoặc 01674630203
email: 8264@donga.edu.vn
mong sớm nhận được câu trả lời từ các bạn!!

Minh Beo
10-03-2010, 08:23
Bạn nên chứa chúng vào 2 mảng, 1 mảng chẵn, 1 lẻ. Sau đó sắp xếp các mảng theo ý muốn. Rồi ghép chúng lại với nhau là xong.
Chúc làm được.

hoan_it
13-03-2010, 17:49
ban len duyet tu dau den cuoi kiem tra tu dau mang den cuoi mang tu 0->spt mang
neu no la chan thi thoi con neu no la le thi doi cho cho cac phan tu dang sau no la ok

hatuyetlan
13-03-2010, 22:05
Có ai biết về Stack không chỉ mình với!

meocon67
17-03-2010, 19:43
có ai có bài tập và bài giải về cơ sở dữ liệu hok,cho e xin,e cần gấp lắm mấy bác ơi !!!! HELP ME >___<

L.T.H
19-03-2010, 15:54
bạn nào biết viết cái này không giúp minh với :
đề tài : quản lý danh sách hóa đơn viết bằng c++
cám ơn nhiều

Than Dieu
21-03-2010, 00:23
Duyệt cây trên C++ (http://forums.congdongcviet.com/showthread.php?t=7105)

Cấu trúc dữ liệu và giải thuật đây (http://forums.congdongcviet.com/forumdisplay.php?f=11)

hahieua017
11-04-2010, 14:34
hữu hà xin chào các anh(chị)!muốn nhờ các anh chị giúp đỡ về bài cấu trúc dữ liệu và giải thuật?
bài tậpp như sao >
Viết chương trình nhập vào 2 danh sách liên kết sau đó sắp xếp danh sách theo thứ tự tăng dần.rồi trộn 2 danh sách trên thành 1 danh sách thứ 3 sao cho vẫn đãm bảo danh sách có thứ tự tănng dần....>??
kính mong các anh (chị )giúp đỡ cho e nhé???viết bằng passcal nhé
thank!

Tadius.ffx
11-04-2010, 16:20
Em à. Ở đây chỉ bàn giải pháp, không phải là giải bài hộ nhé.
Muốn là được trước tiên em phải cài được cái cấu trúc dữ liệu bằng danh sách liên kết trong Pascal đã hiểu nó hoạt động ra sao rồi sau này mới cài sắp xếp, trộn được. Đừng bao giờ có tư tưởng làm hộ. Như vậy chỉ khiến ta ngày càng lười biếng và dốp nát đi mà thôi.

hahieua017
12-04-2010, 08:33
ý em nói là anh(chi)hãy cho e biết phương pháp để viết thui. e đang học về nó và cô đang giao bài tập về làm nhưng đến jo e vân chưa hiêu nhiều về bài tập này mong anh(chị)giúp đỡ và chỉ giáo cho e?
gmail hahieua017@gmail.com có j anh(chị)fun giúp e nhé!
thank!

[=========> Bổ sung bài viết <=========]

chào ?? sao cả diễn đàn ko ai giúp đc mình cả vậy??bùn quá àh?bùn tuần sao nạp bài rùi mà chả ai giứp ca nhi?

nvtpthh
13-10-2010, 14:24
có ai biết làm toán giải tích phân không vậy