从头开始删除单链表节点怎么做?我的delete函数出错了但不知道怎么改

输入样列:
OUT
IN 1000001 Ordinary
IN 2000003 VIP
IN 2000009 VIP
OUT
OUT
IN 2000008 VIP
LIST
QUIT
输出样列:
FAILED:
IN:1 1000001 Ordinary 0
IN:2 2000003 VIP 1
IN:3 2000009 VIP 2
OUT:1 1000001 Ordinary
OUT:2 2000003 VIP
IN:4 2000008 VIP 1
LIST:
3 200000 9VIP
4 2000008 VIP
GOOD BYE!


#include<bits/stdc++.h>
using namespace std;
int n=0;
typedef struct Student{
    int k;
    int wait;
    char id[20];
    char type[20];
    struct Student* next;
}Student;
Student* createList()
{
    Student *L;
    L=(Student *)malloc(sizeof(Student));
    L->next=NULL;
    return L;
}
void inputSingle(Student *s){
    cin>>s->id>>s->type;
    n++;
    s->k=n;
    s->wait=n-1;
}
void outputSingle(Student *s){
    cout<<s->k<<" "<<s->id<<" "<<s->type<<" "<<s->wait<<"\n";
}
void insertTail(Student *L,Student *s)
{
    Student *pre,*p;
    pre=L;
    p=L->next;
    while(p!=NULL){
        pre=p;
        p=p->next;
    }
    s->next=pre->next;
    pre->next=s;
}
void outputList(Student *L){
    Student *p;
    p=L->next;
    while(p!=NULL){
        outputSingle(p);
        p=p->next;
    }
}
int Delete(Student *L)
{
    Student *pre,*p;
    pre=L;
    p=L->next;
    while(p!=NULL){
        pre->next=p->next;
        free(p);
    }
    if(p==NULL){
        puts("FAILED");
        return 0;
    }
    return 1;
}
int main()
{
    Student *L,*s;
    L=createList();
    string order;
    while(1){
        cin>>order;
        if(order=="IN"){
            printf("IN:");
            s=(Student *)malloc(sizeof(Student));
            inputSingle(s);
            outputSingle(s);
            insertTail(L,s);
        }
        if(order=="LIST"){
            printf("LIST:\n");
            outputList(L);
        }
        if(order=="OUT"){
            Delete(L);
        }
        else if(order=="QUIT"){
            puts("GOOD BYE!");
            break;
        }
    }
    return 0;
}
 
 
 

修改处见注释,供参考:

//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int n=0;
typedef struct Student{
    int k;
    int wait;
    char id[20];
    char type[20];
    struct Student* next;
}Student;
Student* createList()
{
    Student *L;
    L=(Student *)malloc(sizeof(Student));
    L->next=NULL;
    return L;
}
void inputSingle(Student *s){
    cin>>s->id>>s->type;
    n++;
    s->k=n;
    s->wait=n-1;
}
void outputSingle(Student *s){
    cout<<s->k<<" "<<s->id<<" "<<s->type<<" "<<s->wait<<"\n";
}
void insertTail(Student *L,Student *s)
{
    Student *pre,*p;
    pre=L;
    p=L->next;
    while(p!=NULL){
        pre=p;
        p=p->next;
    }
    s->next=pre->next;
    pre->next=s;
}
void outputList(Student *L){
    Student *p;
    p=L->next;
    while(p!=NULL){
        outputSingle(p);
        p=p->next;
    }
}
Student* Delete(Student *L) //修改
{
    Student *pre,*p;
    pre=L;
    p=L->next;
    if(pre == NULL || p == NULL)//修改
       return NULL;             //修改
    pre->next = p->next;
    return p;                   //修改
}
int main()
{
    Student *L,*s;
    L=createList();
    string order;
    while(1){
        cin>>order;
        if(order=="IN"){
            printf("IN:");
            s=(Student *)malloc(sizeof(Student));
            inputSingle(s);
            outputSingle(s);
            insertTail(L,s);
        }
        if(order=="LIST"){
            printf("LIST:\n");
            outputList(L);
        }
        if(order=="OUT"){
            s = Delete(L);    //修改
            if(s){            //修改
               printf("OUT:");
               outputSingle(s);//修改
               free(s);
            }
            else{             //修改
               puts("FAILED:");
            }
        }
        else if(order=="QUIT"){
            puts("GOOD BYE!");
            break;
        }
    }
    return 0;
}