简体   繁体   English

c ++中文本编辑器的链接列表

[英]Linked list for text editor in c++

Im trying to write a text editor in c++. 我试着用c ++编写一个文本编辑器。 And each line of text has to go into a node of a linked list. 每行文本都必须进入链表的节点。 Ive got must of the linked list finished, all I need now is how to put each line of text into each node. 我已经完成了链表的必备,我现在需要的是如何将每行文本放入每个节点。 Thats my question, how to put each line of text into each node. 这就是我的问题,如何将每行文本放入每个节点。

Here's my code: 这是我的代码:

typedef int ListItemType;

typedef Strac Node* NodePtr;

Struc Node
{
    ListItemType data;
    NodePtr next;
};

int main()
{
    //Create empty list
    NodePtr head = NULL;

    //1st node
    head = new Node;

    //Initialize the field
    head -> data = ?;

    head -> next = NULL;

    //2nd node
    head -> next = new Node;

    //Initialize the field
    head -> next -> data = ?;

    head -> next -> next = NULL;


}

Im guessing that each line of text goes where the question marks are at? 我猜每行文字都在问号所在的位置?

Thanks 谢谢

Text Editors generally back their editing buffer with a Rope data structure 文本编辑器通常使用Rope数据结构支持其编辑缓冲区

Furthermore, there is a standard doubly linked list data structure in C++ called std::list. 此外,C ++中有一个标准的双向链表数据结构,称为std :: list。

If you want to represent a single line of text perhaps you should use a std::string: 如果你想表示一行文本,也许你应该使用std :: string:

typedef std::string ListItemType;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM