我有一个字符串数组,我应该用它来创建一个链表。问题是我只能使用数组。我查找的所有内容都说使用结构和节点,我不确定从这里去哪里。我知道我的代码不正确,每个指针都指向数组的一个元素,因此它们并没有真正链接。如果有人能指出我正确的方向,那就太棒了
这是我到目前为止所拥有的
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string names [4] = {"Dick", "Harry", "Sam", "Tom", " "};
string *nameptr[4];
for(int x = 0; x < 4; x++)
{
nameptr[x] = &names[x];
cout << *nameptr[x] << " is at position " << x << " and points to ";
cout << &nameptr[x] << endl;
}
return 0;
}