单链表循环基本操作输出结果与预期输出不一样

可不可以帮忙改一下代码


#include <stdio.h>
#include <stdlib.h>
struct node
{//链表结点类型,包含一个存放整型数据的 data 成员,和一个指向下一个结点的next成员
    int data ;
    struct node *next ;   
};

//第一关代码
struct node *createRlist()
{//函数功能:创建一个有一个空循环链表,返回值为头指针
     struct node *head = (struct node *)malloc(sizeof(struct node));
   head->next = head ;
   return head ;
}


struct node * insertOrder(struct node *list, int insData)
{
 //在单向递增有序的循环链表(表头指针list)中插入数据元素insData,使之依然有序 。返回值是头指针
     struct node *p = (struct node *)malloc(sizeof(struct node));
    p->data = insData ;

if(list->next == list || list->next->data > insData)  
  {  
      p->next  = list->next ;  
      list->next = p;   
  }  
  else  
  {  
  struct node *q = list  ;  
  while(q->next!=list && q->next->data < insData)  
    q = q->next ;  
  p->next = q->next ;  
  q->next = p ;    
  }  
    
}

int deleteData(struct node  *list, int delData)
{
    //在单向递增有序循环链表(表头指针list)中删除所有值为delData的结点,返回值为删除结点的个数
     struct node *p =list,*q;
    while (p->next!=list && p->next->data < delData)
     p = p->next ;
    if(p->next ==  list || p->next->data > delData) return 0;
    else
    {
        int count = 0;
        q = p->next ;
        while(q!=list && q->data == delData)
        {
           q = q->next ;
           count++;
        }
       p->next = q;
       return count;
    }
    
}

void printRlist(struct node *list)
{
 //从链表第一个结点开始输出单向循环链表中各数据元素的值,每输出一个数据元素空一格
      struct node *q = list->next ;
    while(q!=list)
     {
         printf("%d ",q->data);
         q = q->next;
     }
}

int destroyRlist(struct node *list)
{
    //从第一个结点开始释放循环链表各结点占用的空间,返回值为最后一个结点的值
    
       struct node *p = list->next ;
    int k ;
    while(list->next!=list)
     {
         p = list->next ;
         list->next = p->next ;
         k = p->data ;
         free(p);
     }
    return k;

}

img

img

要求是啥啊?

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632