📄 linked_list.h
字号:
/************************************************************ * Threads Library Extras * ---------------------- * * Linked List with Header - this class will help on dealing with linked lists with header * * Last Update: Oct 17th 2001 * * Author: Cass Surek <cass@surek.com.br> * and * Orn E. Hansen <oe.hansen@gamma.telenordia.se> * ************************************************************///#include "threads.h"#include <string>//namespace cpp_threads { // To be fixed/** * This class helps you on creating Linked Lists with Header. */ class Node
{
private:
class Node *
_prev; class Node * _next;
bool _head; // To mark the node as a header public:
/** * Initializes the list very clean (no previous, no next, not a header) */ Node(); /** * Initializes the Node and adds it at the end of the list @param Header_p The header of the list this new node should be added to */ Node(class Node * Header_p); /** * The destructor will unlink the Node */ ~Node(); /** * An old fashioned iterator @return a pointer to the previous Node */ class Node *
getPrev(); /** * An old fashioned iterator @return a pointer to the next Node */ class Node * getNext();
/** * Links the current Node to the previous Node @param PrevNode_p the pointer of the previous Node @return true for success, false for failure */ bool
setPrev(class Node *PrevNode_p);
/** * Links the current Node to the next Node @param NextNode_p the pointer of the next Node @return true for success, false for failure */ bool setNext(class Node *NextNode_p);
/** * Checks if the current node is the Header of the list @return true if the Node is the Header, false otherwise */ bool isHeader(); /** * Set the current Node as the Header of the list <BR>It will only work if the node is the only Node in a list, in other words, you can't set a Node from the middle of the list to Header. This would break the list. @return true if the Node is the Header, false otherwise */ bool setHeader(); /** * Gets the Header @return a pointer to the header */ class Node *
getHeader(); /** * Gets the first node after the Header @return a pointer to the first Node after the header Node Note: if there's no node after the header, 0 will be returned */ class Node *
getStart(); /** * Gets the last node @return a pointer to the last Node after the header Node */ class Node * getEnd();
/** * This method will return the number of nodes inside the list * excluding the Header Node @return number of nodes in this list */ int
CountNodes(); /** * This method adds a Node before the current Node * <BR>If the current Node is the Header, it'll insert it after it @param NewNode_p The new Node to be added @return a pointer to the new node */ class Node *
AddBefore(class Node *NewNode_p);
/** * This method adds a Node after the current Node @param NewNode_p The new Node to be added @return number of nodes in this list */ class Node * AddAfter(class Node *NewNode_p);
/** * This method adds a Node at the end of the list. @param Header_p The list header (use 0 to use the current Node as the header) @param NewNode_p The new Node to be added @return a reference to the newly added Node */ class Node * AddAtEnd(class Node *Header_p, class Node *NewNode_p);
/** * This method will return a pointer to the Nth Node <BR> IT can also go to the position relative to the current node @param LinkNode_p The list header (or 0 for the current node) @param Position_p The position of the Node on the list @return a reference to the Nth Node */ class Node * getPos(class Node *LinkNode_p, int Position_p);
/** * This method will destroy the whole list, thus freeing the allocated space <BR>Note: This can only be done through the list Header @param Header_p The Header Node @return true for success, false otherwise */ bool DestroyList(class Node *Header_p);
};
//}; // namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -