Em khai báo các hàm trong ctdl giống y hệt trong giáo trình nhưng sau vẫn bị lỗi. Mấy a giải thích giùm e với.
Mã:
//Khai bao
#include<conio.h>
#include<stdio.h>
#include<alloc.h>
typedef int ElementType;
typedef struct Node
{
ElementType Element;
Node* Next;
};
typedef Node* Position;
typedef Position List;
//Tao danh sach rong
void MakeNullList (List *Header)
{
(*Header) = (Node*)malloc(sizeof(Node));
(*Header) -> Next = NULL;
}
//Kim tra ds rong
int EmptyList (List L)
{
return L->Next == NULL;
}
//Them pt vao vi tri p
void InsertList (ElementType X, Position P, List *L)
{
Position T;
T = (Node*) malloc (sizeof(Node));
T->Next->Element = X;
T->Next = P->Next;
P->Next = T;
}
//Xoa pt tai vi tri p
void DeleteList (Position P, List L)
{
if(P->Next != NULL)
{
Position T;
T->Next = P->Next;
P->Next = P->Next->Next;
free(T);
}
else
printf("
Danh sach rong, khong the xoa!");
}
//Tim vi tri pt X dau tien trong ds
Position Locate(ElementType X, List L)
{
Position P = L;
int found = 0;
while (P->Next != NULL && found==0)
{
if(P->Next->Element == X)
found = 1;
else
P = P->Next;
}
return P;
}
//Lay noi dung phan tu tai vi tri p
ElementType Retrieve(Position P, List L)
{
return P->Next->Element;
}
//Tra ve vi tri dau tien cua ds
Position FirstList (List L)
{
return 1;//Bị lỗi chỗ này/!\
}
//Tra ve vi tri cuoi cung trong ds
Position EndList (List L)
{
Position P=FirstList(L);
while (P->Next != NULL)
P = P->Next;
return P;
}
//Nhap ds L tu ban phim
void ReadList (List *L)
{
ElementType X;
int n;
printf("
Nhap so luong phan tu trong ds: ");
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
printf("
Phan tu thu %d: ",i);
scanf("%d",&X);
InsertList(X,EndList(*L),L);
}
}
//In ds ra man hinh
void PrintList (List L)
{
Position P = FirstList(L);
while(P->Next != NULL)
{
printf("\t%d",Retrieve(P,L));
P = P->Next;
}
}
//Chuong trinh chinh kiem tra
void main()
{
clrscr();
List L;
MakeNullList (&L);
printf("Nhap ds!
");
ReadList(&L);
printf("
Xuat ds vua nhap!
");
PrintList(L);
getch();
}
View more random threads:
Ngoại trừ một số ít trường hợp rãnh mũi - má và “râu rồng silicon” xuất hiện sớm, có khi từ tuổi thanh niên do cơ địa, còn lại, đại đa số do căn do lão hoá đã gây nên ba diễn biến: Giảm mô xương gò...
Cách thẩm mỹ má ở tuổi trung niên...