Home > Back-end >  Bosses, refer to the c + +
Bosses, refer to the c + +

Time:05-26

# include
# include
using namespace std;
# define ok 0
# define the error - 1
# define Max 7
Typedef char typeelem;
Typedef int the status;
Typedef struct no
{
Struct no * next;
Typeelem data;
} noe, * noa;
Typedef struct noc
{
Noa tail and head;
Int leng.
} sqlist;
The status initlist (sqlist & amp; L);//create an empty chain linear table
The status shuzhi (sqlist & amp; L);//to create the Max size chain table table
The status traverselist sqlist (L);//to traverse the chain table
The status getelem (sqlist L, int I);//in the chain table will remove the element I
The status locateelem (sqlist L, typeelem e, int c);//in the chain in the table to find the value of e values of the nodes and for the first c
The status listinsert (sqlist & amp; Int L, d, typeelem a);//chain table insert value
The status listdelete (sqlist & amp; L, int b);//delete the value of b node
The status nextelem (sqlist L, typeelem e);
The status priorelem (sqlist L, typeelem e);
The status clearlist (sqlist & amp; L);
The status destroylist (sqlist & amp; L);

Int main ()
{
Sqlist L;
Int I, d, c, b;
Typeelem e, a,
Initlist (L);
Cout & lt; <"Put Max=" & lt; <" "& lt; Shuzhi (L);
/* cout & lt; <"Traverselist" & lt; Traverselist (L);
Cout & lt; <"Put the I from 1 -" & lt; Cin & gt;> i;
Getelem (L, I);
Cout & lt; <"Seek number c and elem e" & lt; Cin & gt;> e;
/* locateelem (L, e, c);
Cout & lt; <"Listinsert" & lt; <"Put nuumber d" & lt; Cin & gt;> d;
Cout & lt; Cin & gt;> a;
Listinsert (L, d, a);
Cout & lt; <"Traverselist" & lt; Traverselist (L);
Cout & lt; <"Listdelete" & lt; <"Put the number" b & lt; Cin & gt;> b;
Listdelete (L, b);
Cout & lt; <"Nextelem" & lt; Nextelem (L, e);
Priorelem (L, e);
Clearlist (L);
Destroylist (L);
//cout & lt; <"Traverselist" & lt; Traverselist (L);
return ok;
}
The status initlist (sqlist & amp; L)
{
L.h ead=new noe [1].
if(! L.h ead)
{
Cout & lt; <" \ bfailure to open up space "& lt; Return the error;
}
The else
L.t ail=L.h ead;
L.l eng=0;
}
The status shuzhi (sqlist & amp; L)
{
Noa q;
L.l eng=Max;
for (int i=0; I & lt; L.l eng; I++)
{
Q=new noe [1].
if (! Q)
{
Cout & lt; <"Failure to open up space" & lt; Return the error;
}
Cin & gt;> Q - & gt; The data;
L.t ail - & gt; Next=q;
L.t ail=q;
Q - & gt; Next=NULL;
}
return ok;
}
The status traverselist sqlist (L)
{
Noa p;
P=L.h ead - & gt; Next;
If (p==NULL)
{
Cout & lt; <"The list is empty" & lt; Return the error;
}
for (int i=0; I & lt; L.l eng; I++)
{
Cout & lt;

P=p - & gt; Next;
}
return ok;
}
The status getelem (sqlist L, int I)
{
Int j;
Noa q=L.h ead;
If (max{
Cout & lt; <"I is the error" & lt; Return the error;
}
The else
For (j=1; J & lt;=I; J++)
{
Q=q - & gt; Next;
}
Cout & lt; return ok;
}
The status locateelem (sqlist L, typeelem e, int c)
{
C=1;
Noa q=L.h ead - & gt; Next;
While (q - & gt; The data!=e & amp; & Q - & gt; Next!=NULL)
{
Q=q - & gt; Next;
C + +;
}
If (q - & gt; The data!=e)
{
Cout & lt; Return the error;
}
The else
{
Cout & lt; <"The potition is" & lt; Cout & lt; return ok;
}

}
The status listinsert (sqlist & amp; Int L, d, typeelem a)
{
int i;
Noa q=L.h ead - & gt; Next;
Noa p=new noe [1];
for (i=1; i{
Q=q - & gt; Next;
}
P - & gt; Data=https://bbs.csdn.net/topics/a;
P - & gt; Next=q - & gt; Next;
Q - & gt; Next=p;
L.l eng++;
}
The status listdelete (sqlist & amp; L, int b)
{
int i;
If (b<1 | | b> L.l eng)
Return the error;
Noa p=L.h ead - & gt; Next;
Noa q;
For (I=1; I & lt; B - 1; I++)
{
P=p - & gt; Next;
}
Q=p - & gt; Next;
P - & gt; Next=p - & gt; Next - & gt; Next;
The delete [] q;
L.l eng -;
}
The status nextelem (sqlist L, typeelem e)
{
Int c=1;
Noa q=L.h ead - & gt; Next;
While (e!=q - & gt; The data & amp; & Q - & gt; Next!=NULL)
{
Q=q - & gt; Next;
C + +;
}
C + +;
If (c & gt; L.l eng)
{
Cout & lt; return ok; }
The else
{
Cout & lt; Q=q - & gt; Next;
Cout & lt; <"The elem is" & lt; <" "& lt; return ok;
}
}
The status priorelem (sqlist L, typeelem e)
{
Noa q;
Noa p=L.h ead - & gt; Next;
If (e==p - & gt; Data)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull