3_2.txt

来自「C语言数据结构知识原代码 C语言数据结构知识原代码C语言数据结构知识原代码」· 文本 代码 · 共 47 行

TXT
47
字号
#include<stdio.h>
typedef struct node{                   /*结点类型*/
   int data;
   struct node *next;
   }Llist;
insert(Llist **h,int x,int kind)      /*kind=1:插在表头,kind=2:插在表尾*/
                                      /*(*h)为指向表尾的指针*/
{
 Llist *s,*q;
  s=(Llist *)malloc(sizeof(Llist));
  s->data=x;  
  if((*h)->next==*h)                 /*循环链表为空*/
    {
     s->next=*h;
     (*h)->next=s;
     *h=s;
    }
   else
    if(kind==1)
     { q=(*h)->next;
       s->next=q->next;
       q->next=s;
     }
    else{
     s->next=(*h)->next;
     (*h)->next=s;
     *h=s;
    }
  }
  main()
  {
   Llist *h,*p;
   h=(Llist *)malloc(sizeof(Llist));
   h->next=h;
   insert(&h,1,2);
   insert(&h,10,2);
   insert(&h,-1,1);
   p=h->next->next;
   while(p!=h->next){
     printf("%d ",p->data);
     p=p->next;
   }
  }
   
  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?