Home > Back-end >  Small white please help to look at the data structure basis, can't run
Small white please help to look at the data structure basis, can't run

Time:10-16

//merge two orderly singly linked list (only move the pointer), compiled, correct operation failure,

#include

using namespace std;
The template & lt; The class T>
Struct LinkNode {
T data;
LinkNode * link;
};

The template & lt; The class T>
The class List {
Private:
LinkNode * first;
Public:
Void Input ();
Void the Output ();
LinkNode * GetHead const () {return first; }

};

The template & lt; The class T>
Void List : : Input () {
LinkNode * current=first - & gt; The link;
LinkNode * newNode;
NewNode=new LinkNode (a);
Cout<& lt;" Input the list elements: ";
Cin> Current - & gt; The data;
};

The template & lt; The class T>
Void List : : the Output () {
LinkNode * current=first - & gt; The link;
While (current!=NULL) {
Cout<& lt;" "& lt; The current=current - & gt; The link;
}
};

The template & lt; The class T>
Void Combine (List & A, List & B, List & C)
{
LinkNode Atul gawande at the * current1=etHead ();
LinkNode * current2=b.G etHead ();
LinkNode * be sad etHead chtistina georgina rossetti.british poetess current3=();
If (current1 - & gt; The link!=NULL& & Current2 - & gt; The link!=NULL)
{
Current1=current1 - & gt; The link;
Current2=current2 - & gt; The link;
While (current1!=NULL& & Current2!=NULL)
{
If (current1 - & gt; Data{
Current3 - & gt; The link=current1;
Current1=current1 - & gt; The link;
}
The else {
Current3 - & gt; The link=current2;
Current2=current2 - & gt; The link;
}
}
}
};

Void main () {
List L1, L2, L3.
L1. Input ();
L2. Input ();
Cout<& lt;" L1 list as follows: ";
L1. The Output ();
Cout<& lt;" B list as follows: ";
L2. The Output ();
Combine (L1, L2, L3);
Cout<& lt;" M, n after the merger shall be the A: ";
L3. The Output ();
}
  • Related