CodePudding user response:
Of not good, only supplies the reference
#include
#include
Typedef struct NUM
{
Int num.
Struct NUM * next;
} Num.
Void print (Num * p)
{
If (p==NULL) return;
While (p - & gt; Next!=NULL)
{
Printf (" % d ", p - & gt; Num);
P=p - & gt; Next;
}
printf("\n");
}
Int main ()
{
The FILE * FILE;
The file=fopen (" t.t xt ", "r +");
if (! The file)
{
Printf (" file open error! \n");
return 1;
}
Num * p, * head=(Num *) malloc (sizeof (Num));
if (! The head) return 2;
The head - & gt; Next=NULL;
P=the head;
while (! The feof (file))
{
The fscanf (the file "% d", & amp; (p - & gt; Num));
P - & gt; Next=(Num *) malloc (sizeof (Num));
if (! (p - & gt; Next)) return 2;
P=p - & gt; Next;
P - & gt; Next=NULL;
}
The fclose (file);
Print (the head);
Num * t=NULL, * q=(Num *) malloc (sizeof (Num));
if (! Q) the return 2;
The scanf (" % d ", & amp; Q - & gt; Num);
Q - & gt; Next=NULL;
P=the head;
While (1)
{
If (p - & gt; Num & lt; Q - & gt; Num)
{
T=p;
P=p - & gt; Next;
If (p - & gt; Next==NULL)
{
T - & gt; Next=q;
Q - & gt; Next=p;
break;
}
continue;
}
If (p==head)
{
T=head;
The head=q;
The head - & gt; Next=t;
break;
}
The else {
T - & gt; Next=q;
Q - & gt; Next=p;
break;
}
}
Print (the head);
The file=fopen (" t.t xt ", "w +");
if (! The file)
{
Printf (" file open error! \n");
return 1;
}
P=the head;
While (p - & gt; Next)
{
Fprintf (the file "% d", p - & gt; Num);
P=p - & gt; Next;
}
The fclose (file);
}