Home > Back-end >  The access violation... For help
The access violation... For help

Time:10-24

# include & lt; iostream>
using namespace std;

# define MAX_SIZE 10
Typedef int ElemType;

//* * * * * * * * * * * the singly linked list storage structure of * * * * * * * * * * * * *
Struct LNode
{
ElemType data;
Struct LNode * next;
LinkListb LinkLista} * and * and * LinkListc;

Void MergeList (struct LNode *, struct LNode *, struct LNode *);//the function declaration
Void InitList_L (struct LNode *);
Void CreateList_F (struct LNode *, int);

//* * * * * * * * * * * * * * * * * * * * * singly linked lists initialization function * * * * * * * * * * * * * * * * * * * *
Void InitList_L (struct LNode * L)
{
L=new struct LNode;
L - & gt; Data=https://bbs.csdn.net/topics/0;
L - & gt; Next=NULL;
}
//* * * * * * * * * * * * * * * * * * * * * front fork method to construct singly linked lists O (n) * * * * * * * * * * * * * * * *
Void CreateList_F (struct LNode * L, int n)
{
int i=0;
InitList_L (L);
Struct LNode * p;
P=new struct LNode;
cout<" Please according to the topic request, increasing the input integer data "& lt; For (I=n; I & gt; 0; I -)
{
cin> P - & gt; The data;
P - & gt; Next=L - & gt; Next;//this position should be
L - & gt; Next=p;
}
}

Void main ()
{
CreateList_F (LinkLista MAX_SIZE);
CreateList_F (LinkListb MAX_SIZE);
CreateList_F (LinkListc, 0);
MergeList (LinkLista LinkListb, LinkListc);
}

//* * * * * * * * * * * * * * * repeatedly merging incremental data chain table no * * * * * * * * * * * * * * * * * *
Void MergeList (struct LNode * La, struct LNode * Lb, struct LNode * Lc)
{
//merge list (La and Lb, the new table using the head pointer Lc to

Struct LNode * pa, pb, PC, * q;
Pa=La - & gt; Next;
Pb=Lb - & gt; Next;//pa and pb, respectively is the job of the list (LA and LB pointer, initialized to the corresponding list of the first node

Lc=PC=La;//nodes as the head of the LC with the head of the LA

While (pa & amp; & Pb)
{
If (pa - & gt; The data & lt; Pb - & gt; Data)
{
PC - & gt; Next=pa;
Pa=pa - & gt; Next;
}//take smaller elements in LA, connect the PA in the back of the PC and PA pointer back
Else if (pa - & gt; The data & gt; Pb - & gt; Data)
{
PC - & gt; Next=pb;
Pb=pb - & gt; Next;
Smaller}//LB, the elements of the PB links in the back of the PC and PB pointer back
The else
{
PC - & gt; Next=pa;
PC=pa;
Pa=pa - & gt; Next;
Q=pb - & gt; Next;
The delete pb;
Pb=q;
}//equal to take in the LA elements, delete the elements in the LB
}

PC - & gt; Next=pa? Pa: pb;//insert the remaining period of
The delete Lb.//release LB head node

}

CodePudding user response:

It is recommended that you use back?
  • Related