我有一個字符串數組,我應該創建一個鏈表。問題是我只能使用數組。我查過的所有東西都說要使用結構和節點,我不知道該從哪裏去。我知道我的代碼是不正確的,我有指針指向數組中的一個元素,所以它們並沒有真正連接。如果任何人都可以在正確的方向指向我,這將是驚人的無法創建鏈表
這裏是我迄今爲止
#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;
}
有很多關於鏈表的問題......你看了一些指導? – jogojapan 2013-02-18 04:02:51
名稱有5個元素,但你只用4初始化:) – billz 2013-02-18 04:04:17
@blizz 5th是''「''。 – 2013-02-18 04:05:49