Home > Back-end >  The queue to create what's the problem? Garlic guest platform has been not to give, not a test
The queue to create what's the problem? Garlic guest platform has been not to give, not a test

Time:09-20


# # ifndef QUEUE_H_
# define QUEUE_H_
# include
# include "stack. H"

The template
The class Queue {
Private:
//TODO
The Node * front;
The Node * back;
int length;
Void copy (Node * this_, Node * other_);
Void the remove (Node * n);
Public:
The Queue ();
The Queue (Queue & other);
~ the Queue ();
The Queue & operator=(Queue & other);
Const int get_size ();
Void push (T * T);
Void push (Node * n);
The Node * pop ();
Void the print ();
};

# include "queue. CPP
"# endif

# include "queue. H"
# include
The template
The Queue : : Queue ()
{
//TODO
Front back==NULL;
Length=0;
}

The template
The Queue : : Queue (Queue & other)
{
//TODO
If (other. Length==0 | | this==& other)
return;
Length=other. Length;
If (other front==NULL)
{
The front=new Node ();
}
The else
{
The front=new Node (*) (other) front);
Copy (this -> front, other front);
}
If (other back==NULL)
{
The back=new Node ();
}
The else
{
The back=new Node (*) (other) back);
Copy (this -> back, other back);
}
}

The template
The Queue : : ~ Queue ()
{
//TODO
Remove (front);
Remove (back);
}

The template
The Queue & Queue : : operator=(Queue & other)
{
//TODO
If (other. Length==0 | | this==& other)
return;
Length=other. Length;
If (other front==NULL)
{
The front=new Node ();
}
The else
{
The front=new Node (*) (other) front);
Copy (this -> front, other front);
}
If (other back==NULL)
{
The back=new Node ();
}
The else
{
The back=new Node (*) (other) back);
Copy (this -> back, other back);
}
return *this;
}

The template
Int the Queue : : get_size (const)
{
//TODO
Return length;
}

The template
Void Queue : : push (T * T)
{
//TODO
If (t==NULL)
return;
If (length==0)
{
Front back==new Node (T);
The back -> set_next (NULL);
Length++;
return;
}
The else
{
The back -> set_next (new Node (T));
The back=back -> get_next ();
The back -> set_next (NULL);
Length++;
return;
}
}

The template
Void Queue : : push (Node * n)
{
//TODO
If (n==NULL)
return;
If (length==0)
{
The front=back=n;
The back -> set_next (NULL);
Length++;
return;
}
The else
{
The back -> set_next (n);
The back=back -> get_next ();
The back -> set_next (NULL);
Length++;
return;
}
}

The template
The Queue Node * : : pop ()
{
//TODO
If (length==0)
Return NULL;
Else if (length==1)
{
The Node * h=front;
Front back==NULL;
length--;
Return h;
}
The else
{
The Node * h=front;
The front=front -> get_next ();
length--;
Return h;
}
}

The template
Void Queue : : print ()
{
//TODO
Stack * s=new Stack ();
The Node * n=new Node ();
The Node * T=new Node ();
While (length!=0)
{
N=this -> pop ();
S -> push (n);
}
While (s -> get_size ()!=0)
{
T=s -> pop ();
T -> print ();
}
STD: : cout <"END" return;
}
The template
Void Queue : : copy (Node * this_, Node * other_)
{
If (other_ -> get_next ()==NULL)
{
return;
}
This_ -> set_next (new Node (* (other_ -> get_next ())));
Copy (this_ -> get_next (), other_ -> get_next ());
return;
}
The template
Void Queue : : remove (Node * n)
{
If (n==NULL)
{
return;
}
If (n -> get_next ()==NULL)
{
The delete n;
return;
}
The Node * TMP=n -> get_next ();
The delete n;
Remove (TMP);
return;
}
  • Related