我负责编写一个在终端中创建一种文本编辑器的C++程序。文本编辑器由单独的行组成。每条线都必须代表链接列表的成员。我遵循制作两个课程的格式。一个是一行“列表”,另一个是行的类。他们是朋友班。对于每一个新行,创建一个行对象并将其添加到链接列表中。行类的“列表”通过执行诸如插入行和从链表中删除行的操作来管理行对象和链接列表。矢量,字符串或数组?
我的问题是,对于每个单独的行,我应该将它存储为字符数组,字符串还是矢量?
还应该注意的是,行被添加到链接列表后不需要可编辑。它们可以被删除并且可以插入一个新行。 只有三种操作是可能的。将整行插入列表中,将一行添加到列表的末尾,并从列表中删除现有行。创建并添加到列表后,任何给定行的内容都不会被更改。
一些示例输出,我是给定:
1> The first line
2> The second line
3>
4> And another line
5> One more line
6>
7> what do you try to type here?
8>
9>
10>
11> This is the last line
> I 2 ↵
2> This line should be inserted into line number 2
> L ↵
1> The first line
2> This line should be inserted into line number 2
3> The second line
4>
5> And another line
6> One more line
7>
8> what do you try to type here?
9>
10>
11> This line is boring......
12> This is the last line
> I 16 ↵
16> The line number is big BIG
> L ↵
1> The first line
2> This line should be inserted into line number 2
3> The second line
4>
5> And another line
6> One more line
7>
8> what do you try to type here?
9>
10>
11> This line is boring......
12> This is the last line
13>
14>
15>
16> The line number is big BIG
“我的问题是,对于每一行,我应该将它存储为字符数组,字符串还是矢量?”这真的取决于用法。您想要按行执行的所有可能操作的列表是什么?例如:你是否希望能够插入一行中间?你想删除一行的一部分吗?另外,你有限制吗?最大线数或最大线长?请开始准确告诉您要在线路上执行哪些操作。 –
这是一个文本编辑器,所以字符串看起来很合适(对于简单的实现)。 –
提示:考虑让你的程序使用'std :: list'工作,然后如果你的任务需要它编写你自己的具有类似接口的替代列表类(完全相同可能有点困难,因为它可能需要执行'迭代器,这不是一个初学者友好的问)。 –