#include
# include "Linklist. H"
Int main ()
{
Int l;
The link L;
Elemtype e;
Cout & lt;
for (int i=0; I & lt; 10; I++)
{
Cin & gt;> e;
Insert_Linklist (L, 1, e);
}
Traver_Linklist (L);
Cout & lt;
Int n1.
Cout & lt; <"Remove which one position:" & lt; <"";
Cin & gt;> N1.
Delete_Linklist (L, n1, e);
Traver_Linklist (L);
Cout & lt;
Int n2;
Cin & gt;> e;
N2=Locate_Linklist (L, e);
Traver_Linklist (L);
Cout & lt;
Int n3.
Get_Linklist (L, n3, e);
Traver_Linklist (L);
Cout & lt;
Int n4 interchange, a;
Cin & gt;> e;
A=Seek_Linklist (L, n4 interchange, e);
Traver_Linklist (L);
Cout & lt;
Int n5.
Cin & gt;> e;
Change_Linklist (L, n5, e);
Traver_Linklist (L);
Cout & lt;
return 0;
}
The header file:
#include
#include
using namespace std;
# define OK 1
# define the ERROR 0
# define TRUE 1
# define FALSE 0
# define EOF - 1
# define MAXSiZE 100
Typedef int Elemtype;
Typedef int the Status;
//node
Typedef struct Lnode
{
Elemtype date;
Struct Lnode * next;
} Lnode * Link;
//control structure
Typedef struct link
{
Link a head, tail;
int len;
Int isnotInit;
} the link;
//initialize
The Status Init_Linklist (link& L)
{
L.h ead=L.t ail=new Lnode [1].
if (! L.h ead) {return ERROR; }
Don't have any data//head node data fields
L.h ead - & gt; Next=NULL;
L.l en=0;
L.i snotInit=1;
Return OK;
}
//insert
The Status Insert_Linklist (link& L, int I Elemtype e)
{
Int j;
The Link of p, q;
Q=p=L.h ead.
If (L.i snotInit!=1) {return ERROR; }
If (i<1 | | i> L.l en + 1) {return ERROR; }
If (I.=L.l en + 1)
{
For (j=1; J & lt; i; J++) {p=p - & gt; Next; }//for (j=0; jQ=new Lnode [1].
Q - & gt; The date=e;
Q - & gt; Next=p - & gt; Next;
P - & gt; Next=q;
}
If (I==L.l en + 1) {L.t ail=q; }//insert at the end of chain
L.l en++;
Return OK;
}
//delete
The Status Delete_Linklist (link& L, int I Elemtype& E)
{
Int j;
The Link of p, q;
P=L.h ead.
If (L.i snotInit!=1) {return ERROR; }
If (I & lt; 1 | | I & lt; L.l en) {return ERROR; }
If (I.=L.l en)
{
For (j=1; J & lt; i; J++) {p=p - & gt; Next; }
Q=p - & gt; Next;
E=q - & gt; The date;//save node data
P - & gt; Next=q - & gt; Next;
The delete [] q;
}
If (I==L.l en) {L.t ail=p; }
L.l en -;
Return OK;
}
//by value lookup
# if (1)
Int Locate_Linklist (link L, Elemtype e)
{
Int I=1;
If (L.i snotInit!=1) {return ERROR; }
Lnode * p=L.h ead - & gt; Next;//the first node
While (p!=NULL & amp; & P - & gt; The date!=e)
{
P=p - & gt; Next;
i++;
}
If (p - & gt; The date==e) {return I; }
The else
{
Cout & lt; <"The key is not fine!"
}
}
# endif
# if (0)
Lnode * Locate_Linklist (link L, Elemtype key)
{
Lnode * p=L.h ead - & gt; Next;
While (p!=NULL & amp; & P - & gt; The date=={p=p - & gt; key) Next; }
If (p - & gt; The date==key) {return p; }
The else
{
Cout & lt; <"The key is not fine" & lt;
}
}
# endif
The Status Get_Linklist (link& Int L, a, Elemtype& Key)
{
If (L.i snotInit!=1) {return ERROR; }
Lnode * p=L.h ead - & gt; Next;
While (p!=NULL & amp; & P - & gt; The date=={p=p - & gt; key) Next; }
If (p - & gt; The date==key) {key=a; }
The else
{
Cout & lt; <"The key is not fine" & lt;
}
}
//position find
Status Seek_Linklist (link L, int I Elemtype e)
{
If (L.i snotInit!=1) {return ERROR; }
Lnode * p=L.h ead - & gt; Next;
For (int j=0; J & lt; I - 1; J++) {p=p - & gt; Next; }
E=p - & gt; The date;
return e;
}
//position change value
The Status Change_Linklist (link& L, int I Elemtype& E)
{
Int j;
If (L.i snotInit!=1) {return ERROR; }
Lnode * p=L.h ead.
If (i<1 | | i> L.l en) {return ERROR; }
For (j=0; J & lt; I - 1; J++) {p=p - & gt; Next; }
E=p - & gt; The date;
Return OK;
}
Void Traver_Linklist (link L)
{
Lnode * p;
P=L.h ead.
While (p)
{
Cout & lt; P=p - & gt; Next;
}
}
O bosses can you help me to change my
CodePudding user response:
What changed? To change to what look like?