# Include <stdio. h>
# Include <malloc. h>
# Include <conio. h>
# Define error 0
# Define OK 1
# Define equal 1
# Define overflow-1
# Define list_init_size 100
# Define listincrement 10
Struct Stu {
Char name [20];
Char stuno [10];
Int age;
Int score;
} STU [50];
Typedef struct Stu elemtype;
Struct lnode
{
Elemtype data;
Struct lnode * next;
};
Typedef struct lnode;
Typedef struct lnode * linklist;
Int Init (linklist * l)
{
* L = (lnode *) malloc (sizeof (lnode ));
If (! L) Exit (error );
(* L)-> next = NULL;
Return OK;
}/* Init */
Int listlength (linklist L)
{
Int J = 0;
While (L-> next)
{
L = L-> next;
J ++;
}
Return J;
}
Int getelem (linklist L, int I, elemtype * E)
{
Linklist P; Int J;
P = L-> next; j = 1;
While (P & J <I ){
P = p-> next; ++ J;
}
If (! P | j> 1) return error;
* E = p-> data;
Return OK;
}
Int equallist (elemtype * E1, elemtype * E2)
{
If (strcmp (E1-> name, E2-> name) = 0)
Return 1;
Else
Return 0;
}
Int less_equallist (elemtype * E1, elemtype * E2)
{
If (strcmp (E1-> name, E2-> name) <= 0)
Return 1;
Else
Return 0;
}
Int locateelem (linklist la, elemtype E, int type)
{
Int I;
Linklist P;
P = La;
Switch (type)
{
Case equal:
While (p-> next)
{
P = p-> next;
If (equallist (& P-> data, & E ))
Return 1;
}
Return 0;
Break;
Default:
Break;
}
Return 0;
}
Void mergelist (linklist la, linklist LB, linklist * LC)
{
Linklist Pa, Pb, PC;
Pa = La-> next; Pb = LB-> next;
* Lc = pc = La;
While (PA & Pb)
{
If (less_equallist (& pa-> data, & Pb-> data ))
{
PC-> next = PA; Pc = PA; Pa = pa-> next;
}
Else
{
PC-> next = Pb; Pc = Pb; Pb = Pb-> next;
}
}
PC-> next = pa? PA: Pb;
Free (LB );
}
Int printlist (linklist L)
{
Int I;
Linklist P;
P = L;
Printf ("name stuno age score/N ");
While (p-> next)
{
P = p-> next;
Printf ("%-10 S % S/T % d/N", p-> data. Name, p-> data. stuno,
P-> data. Age, p-> data. Score );
}
Printf ("/N ");
}
Int listinsert (linklist L, int I, elemtype E)
{
Linklist P, S;
Int J;
P = L; j = 0;
While (P & J <i-1)
{
P = p-> next;
++ J;
}
If (! P | j> i-1) return error;
S = (linklist) malloc (sizeof (lnode ));
S-> DATA = E;
S-> next = p-> next;
P-> next = s;
Return OK;
}/* Listinsert before I */
Main ()
{
Struct Stu E;
Linklist la, LB, LC;
Clrscr ();
Printf ("/n ------------------- list demo is running... ----------------/n ");
Printf ("first is insertlist function./N ");
Init (& la );
Strcpy (E. Name, "stu1 ");
Strcpy (E. stuno, "100001 ");
E. Age = 80;
E. Score = 1000;
Listinsert (La, 1, E );
Strcpy (E. Name, "stu3 ");
Strcpy (E. stuno, "100002 ");
E. Age = 80;
E. Score = 1000;
Listinsert (La, 2, E );
Printlist (LA );
Getch ();
Strcpy (E. Name, "stu5 ");
Strcpy (E. stuno, "100003 ");
E. Age = 80;
E. Score = 1000;
Listinsert (La, 3, e );
Printlist (LA );
Getch ();
Init (& Lb );
Strcpy (E. Name, "stu2 ");
Strcpy (E. stuno, "100001 ");
E. Age = 80;
E. Score = 1000;
Listinsert (LB, 1, E );
Strcpy (E. Name, "stu4 ");
Strcpy (E. stuno, "100002 ");
E. Age = 80;
E. Score = 1000;
Listinsert (LB, 2, E );
Strcpy (E. Name, "stu6 ");
Strcpy (E. stuno, "100001 ");
E. Age = 80;
E. Score = 1000;
Listinsert (LB, 3, e );
Printlist (LB );
Getch ();
Mergelist (La, LB, & lc );
Printlist (LC );
Getch ();
Printf ("/n/nwelcome to visit http://zmofun.heha.net! /N ");
}