每天水一水 水水更健康

#include <bits/stdc++.h>

using namespace std;

typedef struct Node
{
    int num;
    struct Node *next;
}LinkList;

LinkList* create(int n)
{
    LinkList *p, *q, *head;
    head = p = (LinkList *)malloc(sizeof(LinkList));
    p->num = 1;
    for(int i=2; i<=n; i++)
    {
        q = (LinkList *)malloc(sizeof(LinkList));
        q->num = i;
        p->next = q;
        p = q;
    }
    p->next = NULL;
    return head;
}

void Delete(LinkList *L, int mink, int maxk)
{
    LinkList *p, *pre;
    LinkList *q;
    p = L;
    pre = p;
    p = p->next;
    while(p!=NULL && p->num < maxk)
    {
        if(p->num <= mink)
        {
            pre = p;
            p = p->next;
        }
        else
        {
            pre->next = p->next;
            p = p->next;
        }
    }
}

void print(LinkList *L)
{
    LinkList *p, *q;
    p = L;
    while(p != NULL)
    {
        q = p;
        cout<<p->num;
        p = p->next;
    }
}

int main()
{
    int n;
    LinkList *L;
    cin>>n;
    L = create(n);
    int mink, maxk;
    cin>>mink>>maxk;
    Delete(L, mink, maxk);
    print(L);
    return 0;
}

你可能感兴趣的:(ACM)