[Hàm] Danh sách liên kết đơn (Con trỏ)

#include “stdio.h”
#include “conio.h”
#include “alloc.h”
//Khai bao danh sach lien ket luu tru cac so nguyen==========
typedef int ElementType;
typedef struct Node{
        ElementType Element;
        Node* Next;
//Node* Previous; (DSLK kép)
        };
typedef Node* Position;
typedef Position List;
//Chuong trinh con tao danh sach rong==========
void MakeNull_List *Header){
     (*Header) = (Node*)malloc(sizeof(Node));
     (*Header)->Next = Null;
     }
//Kiem tra danh sach rong (Rong -> 1, nguoc lai -> 0)
int Empty_List(List L){
    return (L->Next == Null);
}
//Them phan tu co noi dung X vao vi tri P trong danh sach L
void Insert_List(ElementType X, Position P, List *L){
     Position T;
     T = (Node*)malloc(sizeof(Node));
     T -> Element = X;
     T -> Next = P -> Next;
     P -> Next = T;
}
//Xoa phan tu tai vi tri P ra khoi L
void Delete_List(Position P, List *L){
     Position T;
     if (P->Next !=Null){
                 T->Next = P->Next;
                 P->Next = P->Next->Next;
                 free(T);
                 }
     else printf(“\nLoi! Danh sach rong khong the xoa!”);
}
// Tim vi tri phan tu X trong danh sach. Neu khong co thi -> EndList(L)
Position Locate(ElementType X, List L){
         Position P;
         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 trong danh sach
ElementType Retrieve (Position P, List L){
            if (P->Next != Null)
            return P->Next->Element;
}
Position First(List L)
{ return L;}
Position EndList(List L)
{Position P;
P=First (L);
while (P->Next!=Null)
{P=P->Next;}
return P;
}
Position
//Nhap danh sach L tu ban phim
void Read_List(List *L)
{int i, n, t;
ElementType X;
Position P;
P=First(*L);
printf(“So phan tu trong danh sach : “); flush(stdin); scanf(“%d”, &n);
for(i=1;i<=n;i++)
{
                 printf(“\nPhan tu thu %d: “, i); flush(stdin); scanf(“%d”,X);
                 Insert_List(X,EndList(*L),L);
                 }
}
//In danh sach ra man hinh
void Print_List(List L){
     Position P;
     P=First(L);
     while (P != EndList(L))
     {
           prnitf(“%d\t”,retrieve(P,L));
           P=P->Next;
           }
}

Kita welcomes your comments...