class Node
{
private:
int value;
Node * prevNode;
Node * nextNode;
public:
Node(int v) ;
Node * a;
Node * b;
Node * c;
Node * setPrevNode(Node * p);
Node * setNextNode(Node * n);
Node * getNextNode() ;
Node * getPrevNode();
void print();
};
Node::Node(int v) {
value = v;
prevNode = NULL;
nextNode = NULL;
}
Node* Node::setPrevNode(Node * p) {
prevNode = p;
return prevNode;
}
Node* Node::setNextNode(Node * n) {
nextNode = n;
return nextNode;
}
Node*Node::getNextNode()
{
return nextNode;
}
Node*Node::getPrevNode()
{
return prevNode;
}
void Node::print()
{
cout << value << "\t";
}
class LinkList
{
private:
Node * head;
Node * value;
Node * a;
Node * b;
Node * c;
public:
LinkList(Node * headNode);
void insert(Node * node);
void del(Node * node);
Node * search(int key);
void print();
};
LinkList::LinkList(Node*headNode)
{
a = NULL;
b = NULL;
c = NULL;
head = headNode;
}
void LinkList::insert(Node * node)
{
a = node;
b = head;
node=node->getNextNode();
node=node->setNextNode(head);
if (head != NULL) {
b = b->getPrevNode();
b = b->setPrevNode(a);
}
head = a;
a = a -> getPrevNode();
a = a->setPrevNode(NULL);
}
Node * LinkList::search(int key)
{
Node * node;
node = head;
while (node != NULL && int(value) != key)
node = node->getNextNode();
return node;
}
void LinkList::del(Node * node)
{
a = node;
a= a -> getNextNode(); //next x
b = node;
b= b->getPrevNode(); // prev x
c = b; //prev x
if (b != NULL)
{
c=c->getNextNode();
c = c->setNextNode(a);
}
if (a != NULL) {
a=a->getPrevNode();
a = a->setPrevNode(b);
}
}
void LinkList::print()
{
if (head != NULL)
{
head->print();
Node * currentNode = head;
while (currentNode->getNextNode() != NULL)
{
currentNode->print();
currentNode = currentNode->getNextNode();
}
}
}
你为什么在set**Node的时候要返回值呢?这会让你当前指针发生变化,你再仔细想想
你好 你这个问题可以参考我的博客帖子http://blog.csdn.net/dong_18383219470/article/details/52437536。希望对你有帮助 望采纳