#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之外。 –