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

/ / 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
      Printf("Empty List");
            Printf("%d ",p->data);
Int main()
    LinkList CL;
    ElemType min,max;
    If(ListCreate_CL(CL)!= OK)
       Printf ("Circular list creation failed!!!\n");
       Return -1;
    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.


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;
        return 0;
    for(int i=1; i<=n; i++)
        int x;
        t=(LinkList) malloc(sizeof (LinkList) );
        t->data = x;
        t->next = CL;
        p->next = t;
    return true;

void ListDelete_CL(LinkList &CL,ElemType min,ElemType max)
    LinkList p = CL;
    if(p->next == CL)
    if(min == max)
        LinkList t =p->next;
        p->next = t;