Home > Back-end >  Everyone a great god see my program which there is an error? There is something wrong with the inser
Everyone a great god see my program which there is an error? There is something wrong with the inser

Time:09-26

#include
#include
#include
# define LEN sizeof (struct DNodelist)
using namespace std;
Typedef struct DNodelist//define structure
{
int data;//node data fields
The prior struct DNodelist *;//nodes forward pointer
Struct DNodelist * next;//after the node to the pointer
} DNodelist;
//function declaration section
Void Error (char * s);//error handling function
DNodelist * Creat_DNodelist (void);//create a two-way chain table function
Void Insert_DNodelist (DNodelist & amp; L, int, int) e;//to double linked list in the ith node insert element e
Void Delete_DNodelist (DNodelist & amp; L, int, int) e;//remove the ith a node element in the list, and e return
Int GetLength_DNodelist DNodelist (l);//the length of the two-way linked list
Void FreeMemory_DNodelist (DNodelist * l);//release of two-way linked list
DNodelist * Find_DNodelist (DNodelist & amp; L, int I);//find the list of the ith node, and returns the node pointer
Void Modly_DNodelist (DNodelist & amp; L, int e);//to find a double linked list data fields for e element node, and will give the position output
Void Print_DNodelist (DNodelist & amp; L);//show the bidirectional data domain elements in the list
//function to write some
Void Error (char * s)
{
Cout & lt; & lt; S & lt; & lt; Endl;
exit(1);
}
DNodelist * Creat_DNodelist (void)
{
Int I, length=0, data=https://bbs.csdn.net/topics/0;
DNodelist * Tail=NULL;
DNodelist * pnew=NULL;
DNodelist * head=(DNodelist *) malloc (LEN);
If (NULL==head)
The Error (" position Error!" );
The head - & gt; Data=https://bbs.csdn.net/topics/0;
The head - & gt; The prior=NULL;
The head - & gt; Next=NULL;
Tail=head;
Cout & lt; & lt; "Please input you want to create the length of the list:";
Cin & gt;> Length;
For (I=1; i{
Pnew=(DNodelist *) malloc (LEN);
If (NULL==pnew)
The Error (" position Error!" );
Cin & gt;> The data;
Pnew - & gt; Data=https://bbs.csdn.net/topics/data;
Pnew - & gt; Next=NULL;
Pnew - & gt; The prior=Tail;
Tail - & gt; Next=pnew;
Tail=pnew;
}
return head;
}
Int GetLength_DNodelist DNodelist (l)
{
Int length=0;
DNodelist * pt=l.n ext.
While (pt!=NULL)
{
Length++;
Pt=pt - & gt; next;
}
Return length;
}
DNodelist * Find_DNodelist (DNodelist & amp; L, int I)
{
DNodelist * prev=& amp; l;
If (prev==NULL)
The Error (" position Error!" );
Int j=1;
While ((prev - & gt; Next!=NULL) | | (j & lt; I))
{
Prev=prev - & gt; next;
j++;
}
If ((prev - & gt; Next==NULL) | | (j & gt; I))
return NULL;
The else
Return prev.
}
Void Insert_DNodelist (DNodelist & amp; L, int, int) e
{
DNodelist * prev=Find_DNodelist (l, I);
DNodelist * PTR=(struct DNodelist *) malloc (LEN);
PTR - & gt; Data=https://bbs.csdn.net/topics/e;
Prev - & gt; The prior - & gt; Next=PTR;
PTR - & gt; The prior=prev - & gt; The prior;
PTR - & gt; Next=prev;
Prev - & gt; The prior=PTR;
}

Void Delete_DNodelist (DNodelist & amp; L, int, int) e
{
DNodelist * prev=Find_DNodelist (l, I);
E=prev - & gt; The data;
Prev - & gt; The prior - & gt; Next=prev - & gt; next;
Prev - & gt; Next - & gt; The prior=prev - & gt; The prior;
Cout & lt; & lt; "Remove elements is:" & lt; & lt; e;
The delete prev.
}

Void Modly_DNodelist (DNodelist & amp; Int l, e)
{
DNodelist * prev=l.n ext.
If (prev==NULL)
The Error (" position Error!" );
Int k=1;
While ((prev - & gt; Next!=NULL) & amp; & (prev - & gt; The data!=e))
{
Prev=prev - & gt; next;
k++;
}
Cout & lt; & lt; "Element e position in the list is:" & lt; & lt; K & lt; & lt; Endl;
}

Void Print_DNodelist (DNodelist & amp; L)
{
DNodelist * prev=l.n ext.
If (prev==NULL)
The Error (" the list is empty table!" );
While (prev!=NULL)
{
Cout & lt; & lt; Prev - & gt; The data & lt; & lt; "";
Prev=prev - & gt; next;
}
Cout & lt; & lt; Endl;
}

Void FreeMemory_DNodelist (DNodelist * l)
{
DNodelist * pt=NULL;
While (l!=NULL)
{
Pt=l - & gt; next;
Free (l);
If (NULL!=pt)
Pt - & gt; The prior=NULL;
L=pt;
}
}
/* void Print_DNodelist (DNodelist * l)
{
DNodelist * prev=l - & gt; Next - & gt; Next - & gt; next;
If (prev==NULL)
The Error (" the list is empty table!" );
While (prev - & gt; The prior!=NULL)
{
Cout & lt; & lt; Prev - & gt; The data & lt; & lt; "";
Prev=prev - & gt; The prior;
}
Cout & lt; & lt; Endl;
} */
Int main ()
{
DNodelist * p=NULL;
Int m, n, t, q;
Int e=0;
P=Creat_DNodelist ();
Print_DNodelist (* p).
Cout & lt; & lt; "Please input you want to insert position:";
Cin & gt;> m;
Cout & lt; & lt; "Please input you want to insert elements:";
Cin & gt;> n;
Insert_DNodelist (* p, m, n);
Cout & lt; & lt; "After insert data in the list is:";
Print_DNodelist (* p).
/* cout & lt; & lt; "Please input you want to delete the position:";
Cin & gt;> Q;
Delete_DNodelist (* p, q, e);
Cout & lt; & lt; Chain table data is: after the "delete".
Print_DNodelist (* p).
Cout & lt; & lt; "Please enter to find elements:";
Cin & gt;> t;
Modly_DNodelist (* p, t); */
return 0;
}
  • Related