addStudent函数和mainMenu函数是重要的两个函数.
#include <iostream>
#include <string>
using namespace std;
struct Student
{
string name;
string major;
Student *p_next;
};
Student *addStudent(Student *p_students)
{
Student *p_new_student = new Student;
cout << "Student name: \n";
cin >> p_new_student->name;
cout << p_new_student->name << "'s major: \n";
cin >> p_new_student->major;
Student *p_place_holder = new Student;
Student *p_all_students = new Student;
p_all_students = p_students;
p_place_holder = NULL;
if (p_students == NULL) // Adds the first element to the linked list which was initialized to NULL
{ …Run Code Online (Sandbox Code Playgroud)