Im trying to write a text editor in 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
Furthermore, there is a standard doubly linked list data structure in C++ called std::list.
If you want to represent a single line of text perhaps you should use a std::string:
typedef std::string ListItemType;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.