Home > Back-end >  The realization of the list
The realization of the list

Time:10-19

 


#include
#include
#include Mu e *//* malloc ()
#include/* EOF (=^ Z? OF6), NULL */
#include/* atoi () */
#include
using namespace std;
# define the ERROR 0;
# define OK 1;
Typedef int the Status;
Typedef int ElemType;

Typedef struct Lnode
{
ElemType date;
Struct Lnode * next;
} Lnode * LinList;

The Status Getdate (LinList L, int I)
{
LinList q;
Int j=1;
Q=L - & gt; next;
While (q& & J{
Q=q - & gt; next;
J++;
}
If (j> I | |! Q)
return ERROR;

Return the q - & gt; The date;
}

The Status InsertLin (int I LinList L, ElemType e)
{
Int j=0;
LinList q, p;
Q=L;
While (q& & J{
Q=q - & gt; next;
J++;
}
if(! Q | | j> I - 1)
return ERROR;

P=(LinList) malloc (sizeof (Lnode));
P - & gt; The date=e;
P - & gt; Next=q - & gt; next;
Q - & gt; Next=p;
return OK;
}

The Status DeleteLin (LinList L, int I)
{
Int j=0;
LinList q, p;
Q=L;
While (q - & gt; Next& & J{
Q=q - & gt; next;
J++;
}
if(! (q - & gt; Next) | | j> I - 1)
return ERROR;
P=q - & gt; next;
Q - & gt; Next=p - & gt; next;
Free (p);
return OK;
}

The Status ShowList (LinList L)
{
LinList q;
Int k=0;
Q=L - & gt; next;
While (q)
{
If (k==1)
cout<"';
k=1;
coutQ=q - & gt; next;
}
If (k==0)
{
return ERROR;
}
The else
{
coutreturn OK;
}
}

Void CreateList (LinList * L, int n)
{
LinList q;
int i;
(* L)=(LinList) malloc (sizeof (Lnode));
(* L) - & gt; Next=NULL;
for(i=0; i{
Q=(LinList) malloc (sizeof (Lnode));
cin> Q - & gt; The date;
Q - & gt; Next=(* L) - & gt; next;
(* L) - & gt; Next=q;
}
}

Int main ()
{
Int n, m, I, the Date, t, e;
Char STR [30].
cin> n;
LinList L;
CreateList (& amp; L, n);
cin> m;
While (m -)
{
cin> str;
If (STRCMP (STR, "get")==0)
{
cin> i;
The Date=Getdate (L, I);

If (Date)
coutThe else
cout<" Get the fail "& lt; }
Else if (STRCMP (STR, "delete")==0)
{
cin> i;
T=DeleteLin (L, I);
If (t)
cout<" The delete OK "& lt; The else
cout<" Delete the fail "& lt; }
Else if (STRCMP (STR, "show")==0)
{
T=ShowList (L);
if(! T)
cout<" The Link list is empty "& lt; }
Else if (STRCMP (STR, "insert")==0)
{
cin> I> e;
T=InsertLin (L, I, e);
If (t)
cout<" Insert OK "& lt; The else
cout<" Insert the fail "& lt; }
}
}

CodePudding user response:

WARNING!!!!!! the following content is unknown, the consequence is proud, do not look down left
=========================================================================
This is irrigation machine test post? Where to copy code from, as well as the code, since it is using the standard library. H file, so the first sentence
 # include 

Change
 # include 


C + + builder XE definition _USE_OLD_STL macro cannot compile, oldstl abandoned, all STL has turned towards dinkumware STL, reference Embarcadero QC# : 91178
Stamp? http://qc.embarcadero.com/wc/qcmain.aspx? D=91178
  • Related