C++关于链表删除

我的节点,链表,以及删除操作的函数是这么定义的,为什么在delete temp那里会出错?#include<iostream>using namespace std;class Node{public: Node(); ~Node(); int Num,Math,English,Chinese,Physics,Chemistry,Biology,Total; float Average; char name[10]; Node *head; Node *next;};Node::Node(){ Num=0; Math=0; English=0; Chinese=0; Physics=0; Chemistry=0; Biology=0; Total=Math+English+Chinese+Physics+Chemistry+Biology; Average=(float)Total/6.0; next=NULL; head=NULL;}class List{public: List(); void Clearn(); bool Search(int num); void Addnode(); void Delete(int num); //bool Change(int num); //void Sort();//任意一科排序 void Traversa();private: Node *First;};List::List(){ First=new Node();}bool List::Delete(int num){ Node *temp=First->next; while(temp!=NULL) { if(temp->Num==num) { temp->head->next=temp->next; temp->next->head=temp->head; delete temp; cout<<"您已删除"<<node->name<<"的有关成绩"<<endl; return true; } else { temp=temp->next; } } cout<<"您要删除的"<<num<<"号学生不存在学籍管理系统中"<<endl; return false;}

因为你要删除的值不是通过new出来的,只是一个int类型的指针,所以没有分配内存。你如果要删除只需要把这个值从链表里减出去就可以了追问

抱歉我的C++确实学的不是很好。朋友,我定义的temp确实是指向num的Node ,也就是节点这个类型呀,为什么说是int类型的指针?

温馨提示:内容为网友见解,仅供参考
无其他回答