#include
#include
#include
Typedef int Elemtype;
Typedef struct DuLNode {
Elemtype data;
The prior DuLNode *;
DuLNode * next;
Int freq.
} DuLNode, * LinkList;
DuLNode * LinkListInit ()
{
DuLNode * L;
L=(DuLNode *) malloc (sizeof (DuLNode));
If (L==NULL)
Return NULL;
L - & gt; The prior=NULL;
L - & gt; Next=NULL;
L - & gt; Freq=0;
Return the L;
}
Int LinkListInsert (DuLNode * L, int I Elemtype e)
{
DuLNode * p, * s;
S=(DuLNode *) malloc (sizeof (DuLNode));
S - & gt; Data=https://bbs.csdn.net/topics/e;
S - & gt; The prior=NULL; S - & gt; Next=NULL;
If (I==1)
{
S - & gt; Next=L;
L - & gt; The prior=s;
L=s;
}
The else
{
P=L;
For (int j=1; J & lt; I - 1; J++)
{
P=p - & gt; next;
}
If (p - & gt; Next==NULL)
{
P - & gt; Next=s; S - & gt; The prior=p;
}
The else
{
P - & gt; Next - & gt; The prior=s;
S - & gt; Next=p - & gt; next;
P - & gt; Next=s;
S - & gt; The prior=p;
}
}
return 1;
}
Void PrintList (DuLNode * L)
{
DuLNode * p=L - & gt; next;
While (p!=NULL)
{
Printf (" % 3 d ", p - & gt; The data);
P=p - & gt; next;
}
printf("\n");
}
Void PrintList_s (DuLNode * L)
{
DuLNode * p=L - & gt; next;
While (p!=NULL)
{
Printf (" % 3 d ", p - & gt; The data);
P=p - & gt; next;
}
printf("\n");
While (p!=NULL)
{
Printf (" freq: % d ", p - & gt; Freq);
P=p - & gt; next;
}
printf("\n");
}
DuLNode * LinkListLocate DuLNode * L, Elemtype (e)
{
DuLNode * p * q;
P=L; Q=p - & gt; next;
While (q!=L & amp; & Q - & gt; The data!=e)
Q=q - & gt; next;
If (q!=L)
{
Q - & gt; Freq++;
P=q - & gt; next;
P - & gt; The prior=q - & gt; The prior; Q - & gt; The prior - & gt; Next=p;
P=L - & gt; next;
While (p!=L & amp; & P - & gt; Freq & gt; Q - & gt; Freq)
P=p - & gt; next;
Q - & gt; Next=p; P - & gt; The prior - & gt; Next=q;
Q - & gt; The prior=p - & gt; The prior; P - & gt; The prior=q;
The return of q;
}
The else
return 0;
}
Int main ()
{
DuLNode * head;
Int x, loc;
int i=1;
The head=LinkListInit ();
If (head==NULL)
{
Printf (" initialization list failed! \n");
return 0;
}
Do {
Printf (" please enter the first % d element values (end input please enter 0) : ", i++);
Scanf_s (" % d ", & amp; X);
LinkListInsert (head, I, x);
} while (x!=0);
PrintList (head);
return 0;
}