用C ++编写链表程序

我正在编写一个用于学生记录的链接列表程序。我在显示学生功能的代码中显示当前->下一个错误。我也不确定在switch语句中调用该函数时要传递给什么。感谢您的帮助。我被困住了,因为我无法前进。感谢您的回应。

#include <iostream>
#include <string>
using namespace std;
void Student::Runprog()
{
 char option = ' ';
 cout << "Welcome to the Student record management" << endl;
 cout << "Input a value from the options" << endl;
 cout << "1. Add a student" << endl;
 cout << "2. Search for a student" << endl;
 cout << "3. Delete a student" << endl;
 cout << "4. Display records of student" << endl;
 cin >> option;
 do
 {
 switch (option)
 {
 case '1':
 addstudent();
 break;
 case '2':
 searchstudent();
 break;
 case '3':
 deletestudent();
 break;
 case '4':
 displaystudents();
 break;
 default:
 cout << "Invalid option entered.Input the value again" << endl;
 break;
 }
 } while (option!=5);
}
bool Student::isEmpty(Student* head)
{
 if (head == NULL) 
 return true;
 else 
 return false;
}
void Student::addstudent()
{
 Student* s = new Student;
 cout << "Enter the name of the student" << endl;
 cin >> s->name;
 s->next = nullptr; //indicates that the linkedlist is empty
 if (check) {
 head = s;
 lastptr = s;
 check = false;
 }
 else {
 lastptr->next = s;
 lastptr = s;
 }
 cout << "Recorded successfully added" << endl;
}
void Student::searchstudent()
{
 /*
 Student* previous;
 Student* current;
 int rollnum;
 cout << "Enter the roll number of student" << endl;
 cin >> rollnum;
 previous = head;
 current = head;
 while (current->rollnum != rollnum) {
 previous = current;
 current = current->next;
 }
 cout << "The student name is: " << current->name << endl;
 cout << "The roll number of student is: " << current->rollnum << endl;
 cout << "The discipline of student is: " << current->discipline << endl;
 cout << "The section of the student is: " << current->section << endl;
 */
}
void Student::deletestudent()
{
 /*
 Student* ptr = NULL;
 Student* prev = NULL;
 Student* current = NULL;
 int rollnum;
 cout << "Enter the rollnumber of student to delete" << endl;
 cin >> rollnum;
 prev = head;
 current = head;
 while (current->rollnum!=rollnum)
 {
 prev = current;
 current = current->next;
 }
 prev->next = current->next;
 current->next = NULL;
 delete current;
 cout << "Record sucessfully deleted" << endl;
 */
}
void Student::displaystudents(Student* current)
{
 if (isEmpty(current))
 cout << "The list is empty/n";
 else {
 cout << "The list contains: " << " " << endl;
 while (current != NULL) {
 cout << current->name << endl;
 current = current->next << endl;
 }
 }
}
评论