#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;
}
}
Basically, what I’m doing is creating a linked list and inserting a new node in between node 2 and node 3 and deleting node number 3 out of 4 nodes (note for loop is 4 times).
And the next code after the loop is where I tried using code for insertion of a new node.
But after executing it says incompatible types in assignment of 'int' to char[20]' I don’t understand that.
Also, I wanted to know if my code is correct for the above intention.
I took temp2 to be the 3rd code by linking the newnode to the next node and temp to be the second node…
So can someone explain what the error meant so I can get it right? Thank you!
I did your homework, spend some attention on the comments: