Home > Back-end >  Questions about the c data structure
Questions about the c data structure

Time:09-22

Topic is Boolean operator==(CirDoublyList & List)//* this quite and list are equal, not comparing length
Here are DoubleNode. H header file, textbook copy no problem,
The template & lt; The class T>
The class DoubleNode
{
Public:
T data;
DoubleNode * prev, next;

DoubleNode ()
{
This - & gt; Prev=this - & gt; Next=NULL;
}

DoubleNode (T data, DoubleNode * prev=NULL, DoubleNode * next=NULL)
{
This - & gt; Data=https://bbs.csdn.net/topics/data;
This - & gt; Prev=prev.
This - & gt; Next=next;
}
};
Here are DoubleNode. H header file, the great god, please help to see where there is wrong
#include
using namespace std;
# include "DoubleNode. H"

The template & lt; The class T>
The class CirDoublyList
{
Public:
DoubleNode * the head;

CirDoublyList ();
CirDoublyList (T values [], int n);
~ CirDoublyList ();

Bool empty ();
Int the count ();
Boolean operator==(CirDoublyList & The list);
Bool equals (DoubleNode * p, DoubleNode * q);
T& Get (int I);
Virtual void set (int I, T, x);
Friend ostream& Operator<<> (ostream& Out, CirDoublyList & amp;);
DoubleNode * insert (int I, T, x);
Virtual DoubleNode * insert (T, x);
T remove (int I);
Void removeAll ();
};

The template & lt; The class T>
CirDoublyList : : CirDoublyList ()
{
This - & gt; The head=new DoubleNode (a);
This - & gt; The head - & gt; Prev=this - & gt; The head - & gt; Next=this - & gt; The head;
}

The template & lt; The class T>
CirDoublyList : : CirDoublyList (T values [], int n)
{
This - & gt; The head=new DoubleNode (a);
This - & gt; The head - & gt; Prev=this - & gt; The head - & gt; Next=this - & gt; The head;
for (int i=0; iThis - & gt; Insert (values [I]);
}

The template & lt; The class T>
CirDoublyList : : ~ CirDoublyList ()
{
This - & gt; RemoveAll ();
Delete this - & gt; The head;
}

The template & lt; The class T>
Bool CirDoublyList : : empty ()
{
Return this - & gt; The head - & gt; Next==this - & gt; The head;
}

The template & lt; The class T>
Int CirDoublyList : : the count ()
{
int i=0;
For (DoubleNode * p=this - & gt; The head - & gt; next; P!=this - & gt; The head; P=p - & gt; Next)
i++;
return i;
}

The template & lt; The class T>
T& CirDoublyList : : get (int I)
{
DoubleNode * p=this - & gt; The head - & gt; next;
For (int j=0; P!=this - & gt; Head & amp; & jP=p - & gt; next;
If (i>=0 & amp; & P!=NULL)
The return p - & gt; The data;
Throw out_of_range (" unable to return the value of the I ");
}

The template & lt; The class T>
Void CirDoublyList : : set (int I, T, x)
{
DoubleNode * p=this - & gt; The head - & gt; next;
For (int j=0; P!=this - & gt; Head & amp; & jP=p - & gt; next;
If (i>=0 & amp; & P!=this - & gt; The head)
p-> Data=https://bbs.csdn.net/topics/x;
The else throw out_of_range (" unable to set the value of the I ");
}
The template & lt; The class T>
Ostream& Operator<<> (ostream& Out, CirDoublyList & The list)
{
Out<" (";
For (DoubleNode * p=list. The head - & gt; next; P!=list. The head; P=p - & gt; Next)
{
Out The data;
If (p - & gt; Next!=list. Head)
Out<" , ";
}
Out<" ) \ n ";
Return the out;
}

The template & lt; The class T>
DoubleNode * CirDoublyList : : insert (int I, T, x)
{
DoubleNode * front=this - & gt; The head;
For (int j=0; The front - & gt; Next!=head & amp; & jThe front=front - & gt; next;
DoubleNode * q=new DoubleNode (x, front, front - & gt; Next);
The front - & gt; Next - & gt; Prev=q;
The front - & gt; Next=q;
The return of q;
}

The template & lt; The class T>
DoubleNode * CirDoublyList : : insert (T, x)
{
DoubleNode * q=new DoubleNode (x, this - & gt; The head - & gt; Prev, this - & gt; The head);
This - & gt; The head - & gt; Prev - & gt; Next=q;
This - & gt; The head - & gt; Prev=q;
The return of q;
}

The template & lt; The class T>
T CirDoublyList : : remove (int I)
{
DoubleNode * p=this - & gt; The head - & gt; next;
For (int j=0; P!=this - & gt; Head & amp; & jP=p - & gt; next;
If (i>=0 & amp; & P!=this - & gt; The head)
{
T old=p - & gt; The data;
p-> Prev - & gt; Next=p - & gt; next;
p-> Next - & gt; Prev=p - & gt; Prev.
The delete p;
Return old;
}
Throw out_of_range (" unable to delete the I value ");
}

The template & lt; The class T>
Void CirDoublyList : : removeAll ()
{
DoubleNode * p=this - & gt; The head - & gt; next;
While (p!=this - & gt; The head)
{
DoubleNode * q=p;
P=p - & gt; next;
The delete q;
}
This - & gt; The head - & gt; Next=this - & gt; The head - & gt; Prev=this - & gt; The head;
}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related