Cyclic singly linked list interval deletion

6-1 Circulating single linked list interval deletion (15 points)

This question requires the creation of a circular singly linked list with a leading node and the interval deletion of a singly linked list. L is a circular single-linked list with a leading node. The function ListCreate_CL is used to create a circular single-linked list. The function ListDelete_CL is used to delete linked list elements whose value is greater than min and less than max.

function interface definition:

    Status ListCreate_CL(LinkList &CL); 
    void ListDelete_CL(LinkList &CL,ElemType min,ElemType max);

裁判test program example:

// library function header file contains
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>

/ / Function status code definition
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2

Typedef int Status;
Typedef int ElemType; // Assume that the elements in the linear table are all integers

Typedef struct LNode
{
    ElemType data;
    Struct LNode *next;
}LNode, *LinkList; //The definition of the circular single-linked list type is the same as the definition of the single-linked list, and the difference is the value of the tail node next.

Status ListCreate_CL(LinkList &CL);

Void ListDelete_CL(LinkList &CL, ElemType min, ElemType max);

Void ListPrint_CL(LinkList &CL)
{ // Output a single linked list, output Empty List when empty.
    LNode *p=CL->next; //p points to the first element node
    If(p==CL){
      Printf("Empty List");
      Return;
    }
    While(p!=CL)
    {
        If(p->next!=CL)
            Printf("%d ",p->data);
        Else
            Printf("%d",p->data);
        p=p->next;
    }
}
Int main()
{
    LinkList CL;
    ElemType min,max;
    If(ListCreate_CL(CL)!= OK)
    {
       Printf ("Circular list creation failed!!!\n");
       Return -1;
    }
    Scanf("%d%d",&min,&max);
    ListDelete_CL(CL,min,max);
    ListPrint_CL(CL);
    Return 0;
}

/* Please fill in the answer here */

Input format: The first line enters an integer n, which means the number of elements in the circular single-linked list. The next line has a total of n integers separated by spaces. Enter min and max in the third line.

output format: Outputs the elements of the circular list after deletion. The two elements are separated by spaces, and there is no space after the last element.

入样样:

6
1 2 3 4 5 6
2 5

出样样:

1 2 5 6
Status ListCreate_CL(LinkList &CL)
{
    CL = (LinkList) malloc(sizeof (LinkList));
    CL -> next = CL;
    LinkList p = CL;
    LinkList t;
    int n;
    scanf("%d",&n);
    if(n<0)
        return 0;
    for(int i=1; i<=n; i++)
    {
        int x;
        scanf("%d",&x);
        t=(LinkList) malloc(sizeof (LinkList) );
        t->data = x;
        t->next = CL;
        p->next = t;
        p=t;
    }
    return true;

}
void ListDelete_CL(LinkList &CL,ElemType min,ElemType max)
{
    LinkList p = CL;
    if(p->next == CL)
        return;
    if(min == max)
        return;
    while(p->next!=CL)
    {
        LinkList t =p->next;
        while(t->data>min&&t->data<max)
            t=t->next;
        p->next = t;
        p=t;
    }
}