We're going over linked lists in my class right now. Unfortunately, it's an online class. The only thing the prof is good for is grading, and I can't find the answer in my book. I would like to know if you could create a linked list with multiple pieces of data like this.

struct node{
    char grade
    string student        
    node *next
};

node *newNode;

newNode = new node;
newNode->student = "Jake";
newNode->grade = 'D';//Cause I don't like Jake
newNode->next = NULL;
有帮助吗?

解决方案

Yes. You could have as many types of data in a linked list as you'd need.

struct node{
    char grade
    string student        
    node *next
    typeOfData typeVariableName;
};

node *newNode;

newNode = new node;
newNode->student = "Jake";
newNode->typeVariableName = /*anything could go here*/;
newNode->grade = 'D';
newNode->next = NULL;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top