如何在C ++中制作“双循环链表” [英] How to make 'double circular linked list' in C++"

查看:84
本文介绍了如何在C ++中制作“双循环链表”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好〜

我想了解双循环链表的原理。

我将向您展示C ++代码。 (代码太长了)

我必须实现''List.cpp''但这对我来说太难了。



* Node.h

Hello~
I want to understand the principle of double circular linked list.
I will show you C++ code. (Code is so long)
I have to implement ''List.cpp'' but this is so difficult to me.

* Node.h

#ifndef _NODE_H_
#define _NODE_H_
#include <iostream>
using namespace std;
class Node{
private:
	int data;
	Node *next;
	Node *prev;
public:
	Node(int );
	~Node();
	void Set_next(Node *);
	void Set_prev(Node *);
	Node* Get_next();
	Node* Get_prev();
	void Set_data(int);
	int Get_data();
	void Print();
};
#endif



* List.h


* List.h

#ifndef _LIST_H_
#define _LIST_H_
#include "Node.h"
class List{
private:
	Node *Head;
public:
	List();
	~List();
	void InFt(int );
	void InBk(int );
	bool DelFt(int &);
	bool DelBk(int &);
	void Sort();
	void ShowFt();
	void ShowBk();
	
};

#endif



* Node.cpp


* Node.cpp

#include "Node.h"

Node::Node(int data){
	this->data = data;
	this->next = NULL;
	this->prev = NULL;
}
Node::~Node(){
	cout<<data<<" is deleted"<<endl;
}
void Node::Set_next(Node *next){
	this->next = next;
}
void Node::Set_prev(Node *prev){
	this->prev = prev;
}
Node* Node::Get_next(){
	return next;
}
Node* Node::Get_prev(){
	return prev;
}
void Node::Set_data(int data){
	this->data = data;
}
int Node::Get_data(){
	return data;
}
void Node::Print(){
	cout << data << " " ;
}



* List.cpp


* List.cpp

#include "List.h"

List::List(){
	this->Head = NULL;
}

void List::InFt(int data){
	// insert this part
	// Insert new node at front
}

void List::InBk(int data){
	// insert this part
	// Insert new node at back
}



剩下的代码越多。但我只是想开始第一个功能(InFt)。

我理解单向链表的原理(不是双循环)。但我无法理解''双循环链表''。请帮助我〜


The more code is remained. But I just want to begin the first function(InFt).
I understood the principle of linked list in one-way(not double circular). But I can not understand ''double circular linked list''. Please help me~

推荐答案

从一开始就开始,一步一步。



你有构造函数,所以实现 InFt 函数,并在调试器中测试它。

当它工作时,添加 InBk 功能和测试。在你之前的每个功能都工作之前不要继续使用另一个功能。



继续进行一小段阶段,直到你添加了每个功能,一切正常。< br $> b $ b

这是你的功课!因此,试着试一试 - 这并不困难,如果你遇到特定问题,请随时询问。但我们不打算为你做这一切!
So start at the beginning, and do it one step at a time.

You have the constructor, so implement the InFt function, and test it in the debugger.
When it works, add the InBk function and test that. Do not move on to another function until you have each previous one working.

Keep going in little stages until you have added each and every function and it all works.

It''s your homework! So knuckle down, and give it a try - it''s not that difficult and if you get stuck on specific problem, feel free to ask about it. But we aren''t going to do it all for you!


这篇关于如何在C ++中制作“双循环链表”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆