Home > Back-end >  Empty list function clearList () implementation
Empty list function clearList () implementation

Time:10-24

/*... NodeClass. H... */
# include
using namespace std;
# # ifndef NODE_CLASS_H
# define NODE_CLASS_H
//class declaration section
The template & lt; The class T>
The class Node
{
Private:
Node * next;//pointer to subsequent node
Public:
T data;//data domain
The Node (const T & amp; Item, Node * PTR=NULL);//the constructor
Void insertAfter (Node * p);//nodes after insert a similar in this p
Node * deleteAfter ();//remove the nodes of subsequent class, and returns the address
Node * nextNode () const;//get the subsequent node address

};

//class implements part of the
//the constructor to initialize the data members and pointer
The template & lt; The class T>
Node : : Node (const T& Item, Node * PTR) : data (item), next (PTR)
{

}
The template & lt; The class T>
Node * Node : : nextNode (const)
{
Return next;//return a pointer to private members
}
# endif//NODE_CLASS_H

/*... LinkListClass. H... */
# # ifndef LINK_LIST_CLASS_H
# define LINK_LIST_CLASS_H
# include & lt; iostream>
# include & lt; Stdlib. H>
# include "NodeClass. H"
# # ifndef NULL
Const int NULL=0;
# endif//NULL

The template & lt; The class T>
The class LinkedList
{
Private:
//data members
Node * front, rear;//pointer to the header and footer
Node * currPtr, * prevPtr;//record the current traversing the location of the pointer, the insert and delete operations update
Int size;//the number of elements in the table
Int position;//the current element to the serial number of the position in the table, used by function reset

Public:

//to empty list: the release of all nodes of memory space, and the destructor, operator=call
Void clearList ();
};
# endif//LINK_LIST_CLASS_H

/* below is clearList () function implementation */

# include & lt; iostream>
# include & lt; Stdlib. H>
# include "LinkListClass. H"
using namespace std;
//empty list, release all nodes linked list of memory space, and the destructor, operator=call
The template & lt; The class T>
Void LinkedList : : clearList ()
{
Node * nextPtr;
CurrPtr=front;
//while traversing the delete node
While (currPtr!=NULL)
{
//record the next node address, and delete the current node
NextPtr=currPtr - & gt; NextNode ();
The delete currPtr;
CurrPtr=nextPtr;//make the pointer to the next node
}
The front=currPtr=rear=NULL;
}

The implementation process in vs2010 always appear ERROR: should input statement, ERROR: this declaration is not stored class or type specifier?

Under the great god please help solve? I would be grateful
  • Related