链接列表和双重连结清单 [英] link list & double link list

查看:103
本文介绍了链接列表和双重连结清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数组定义列表,并实现遍历列表

define a list using array , and implement traverse list

推荐答案

"使用数组定义列表,并实现遍历列表". ..,如果您的老师看到此页面,您将注定要失败!
"define a list using array , and implement traverse list" ... and if your teacher sees this page you will be doomed!


定义:

Definition:

class list
{
public:
int data;
list *previous;
list *next;
}



如果此元素没有先前的元素,则previous = NULL.
如果没有该元素的下一个元素,则next = NULL.

添加功能的实现:



If there is no previous elements for this element, then previous = NULL.
If therer is no next elements for this elements, then next = NULL.

Implementation of add function:

class list
{
public:
list()
{
previous = next = NULL;
}
HRESULT add(int parameter_data);
protected:
int data;
list *previous;
list *next;
}
HRESULT list::add(int parameter_data)
{
list *local_list_element = new list;
local_list_element->next = NULL;
local_list_element->data = parameter_data;
local_list_element->previous = this;
if(next==NULL)
{
next = local_list_element;
}
else
{
list *local_copy = next;
local_copy->previous = local_list_element;
next = local_list_element;
local_list_element->next = local_copy;
}
return S_OK;
}


阅读他的书 Robert Sedgewick [ ^ ],该网站上提供了代码...

问候
Espen Harlinn
Read his books Robert Sedgewick[^] , code is provided on the site...

Regards
Espen Harlinn


这篇关于链接列表和双重连结清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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