PDA

View Full Version : Cấu trúc dữ liệu



greencarnation88
26-11-2008, 08:55
Tôi có 1 đoạn code về cài đặt danh sách bằng mảng.Tôi ko biết mình khai báo như vậy có đúng ko?Tại sao khi tôi sử dụng ElementType, Position thì máy đều báo lỗi.Bạn nào biết thì sửa giúp tôi,TÔI ĐANG CẦN GẤP.Cảm ơn rất nhiều.Đoạn code đó đây:
#include<stdio.h>
#include<conio.h>
#define MAX 100
struct List
{
int A[MAX];
int Last;
};
List L;
void MakeNull(List *L)
{
L->Last = 0;
}
void Nhap(int n){
for(int i=0;i<=n-1;i++)
{
printf("Phan tu thu %d: ",i);
scanf("%d",&L.A[i]);
}
}
void In(int n){
for(int i= 0;i<= n-1;i++)
{
printf("%d",&L.A[i]);
printf("\n");
}
}
void Insert_List(int X, Position P,List *L)
{
if(L->Last==MAX)
printf("Danh sach day");
else if((P<1)||(P>L->Last+1))
printf("Vi tri khong hop le");
else{
Position Q;
for(Q=(L->Last-1)+1;Q>P-1;Q--)
L->Elements[Q]=L->Elements[Q-1];
L->Elements[P-1]=X;
L->Last++;
}
}
int main()
{
clrscr();
List L;
ElementType X;
Position P;
MakeNull_List(&L);
Nhap(&L);
printf("Danh sach sau khi nhap:");
In(L);
printf("Phan tu can them: ");scanf("%d",&X);
Printf("Vi tri can them: ");scanf("%d",&P);
Insert_List(X,P,&L);
printf("Danh sach sau khi them:");
In(L);
getch();
return 0;
}