久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

不使用指針的鏈表實現是否可行?

Is a Linked-List implementation without using pointers possible or not?(不使用指針的鏈表實現是否可行?)
本文介紹了不使用指針的鏈表實現是否可行?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我的問題很簡單,是否可以使用 C++,在不使用指針(下一個節點)的情況下實現鏈表數據結構?為了進一步限定我的問題,我的意思是可以僅使用類實例化來創建鏈表數據結構.

My question is very simple, can one using C++, implement a link-list data structure without using pointers (next nodes)? To further qualify my question, I'm mean can one create a Linked-List data structure using only class instantiations.

一個常見的節點定義可能是這樣的:

A common node definition might be like so:

template<typename T>
struct node
{
   T t;
   node<T>* next;
   node<T>* prev;
};

我知道 std::list 等,我只是想知道它是否可能 - 如果有的話如何?代碼示例將不勝感激.

I'm aware of std::list etc, I'm just curious to know if its possible or not - and if so how? Code examples will be greatly appreciated.

更多說明:

  1. 插入應該是 O(1).
  2. 遍歷不應該超過 O(n).
  3. 實節點和空節點應該是可微的.
  4. 鏈表的大小應僅受可用內存量的限制.

推薦答案

當然,如果你不介意鏈表有一個最大大小,你可以靜態分配一個鏈表節點數組,然后使用整數索引到數組作為每個節點的上一個"和下一個"值,而不是指針.我過去這樣做是為了節省一點內存(因為整數可以是 2 或 4 個字節,而在 64 位系統上,指針將是 8 個字節)

Sure, if you don't mind the linked list having a maximum size, you could statically allocate an array of list nodes, and then use integer indices into the array as your "previous" and "next" values for each node, rather than pointers. I've done in this in the past to save a bit of memory (since an integer can be either 2 or 4 bytes, whereas on a 64-bit system a pointer will be 8 bytes)

這篇關于不使用指針的鏈表實現是否可行?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 色爱区综合 | 久久久视频在线 | 亚洲欧美一区二区三区视频 | 国产免费一区二区三区网站免费 | 日韩综合网 | 日韩毛片 | 男人av网 | 久久九九99 | 欧美精品一区在线 | 精品丝袜在线 | 精品久久久久久久久久久 | 欧美日本免费 | a级片网站| 综合网中文字幕 | 国产a爽一区二区久久久 | 91色综合 | 亚洲午夜精品 | 日韩精品一区二区三区在线观看 | 欧美中文字幕一区二区三区亚洲 | 久久久青草婷婷精品综合日韩 | 亚洲黄色av网站 | 久久久高清 | 国内自拍视频在线观看 | 午夜在线 | 日韩一区二区av | 国产偷录视频叫床高潮对白 | 福利视频亚洲 | 黄色中文字幕 | 欧美不卡视频一区发布 | 亚洲一区成人 | 污污的网站在线观看 | 黄色毛片网站在线观看 | 男女在线免费观看 | 日韩爱爱网 | 亚洲天堂中文字幕 | 日韩久久久久 | 欧美中文在线 | 人人干人人草 | 免费看啪啪网站 | 中文字幕在线观看第一页 | 天天影视亚洲综合网 |