#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を削除します(ループは4回です)。 そして、ループの後の次のコードは、新しいノードの挿入にコードを使用しようとしたところです。リンクされたリストを作成する際に、どのようにノードの値を割り当てるのですか?
実行後はincompatible types in assignment of 'int' to char[20]'
と書いてありますが、わかりません。 また、私のコードが上記の意図に合っているかどうかを知りたかったのです。 新しいノードを次のノードに接続し、tempを2番目のノードに接続することでtemp2を3番目のコードにしました...
誰かがエラーの意味を説明できるので、正しく取得できますか?ありがとうございました!
してください...あなたのコードと少し違います... – fpointbin
ありがとうございます。 – Surya
なぜあなたは余分なブレースを使用しているのか分かりません。 'for(/ ** /){/ ** /} {/ ** /} 'となります。また、struct * outside * 'main'を移動する必要があります。 –