#include <iostream>
using namespace std;
int main()
{
struct list
{
string name;
int age;
double height;
list *next;
};
list *first,*temp,*temp2;
for (int i=0 ;i<4;i++)
{
list *newlist;
newlist = new list;
cout << " Enter the name : ";
cin >> newlist->name;
cout << " Enter the age : ";
cin >> newlist->age;
cout << " Enter the height : ";
cin >> newlist->height;
cout << " Name is: " << newlist->name << " " ;
cout << " Age is: " << newlist->age << " ";
cout << " Height is: " << newlist->height <<endl;
}
{
list *newlist1;
newlist1 = new list;
newlist1->name = "Steve";
newlist1->age = 23;
newlist1->height = 2.3;
newlist1->next=temp2;
temp->next=newlist1;
newlist1->next = temp2;
temp->next = newlist1;
temp2 = newlist1->next;
temp2->next = newlist1->next;
delete temp2;
cout << " Name is: " << newlist1->name << " ";
cout << " Age is: " << newlist1->age << " ";
cout << " Height is: " << newlist1->height;
}
}
基本上,我在做的是創建一個鏈表,並在節點2和節點3之間插入一個新節點,並從4個節點中刪除節點號3(注意for循環是4次)。 而循環後的下一個代碼是我嘗試使用代碼插入新節點的地方。創建鏈接列表時如何爲節點分配值?
但執行它後說incompatible types in assignment of 'int' to char[20]'
我不明白。 另外,我想知道我的代碼對於上述意圖是否正確。 我通過將新節點連接到下一個節點並將溫度作爲第二個節點,將temp2作爲第三個代碼...
那麼有人可以解釋錯誤的含義是什麼,這樣我就可以解決它了嗎?謝謝!
請...有點你的代碼... – fpointbin
非常感謝你們。 – Surya
我不確定你爲什麼使用額外的大括號。 '(/ ** /){/ ** /} {/ ** /}'。另外,你應該將結構體*移到* main之外。 –