循环链表

#include<stdio h="">  
#include<string h="">  
#include <malloc h="">  
#include<stdlib h="">  
  
typedef struct Node  
{  
    char data;  
    struct Node *next;  
}node;  
  
node *head=NULL;  
node *p=NULL;  
  
void creat(char c[])  
  
{        
    int i=0;                           
    while(c[i] != '\0')             
    {  
        p = (node*)malloc(sizeof(node));  
        p->next=NULL;  
        p->data=c[i];  
        if(head == NULL)  
        {  
            head = p;  
            head->next = p;  
        }  
        else  
        {  
            p->next = head->next;  
            head->next = p;  
            head = p;  
        }  
        i++;  
    }  
}  
  
void add()  
{  
    char c;  
    scanf(" %c",&c);  
    p = (node*)malloc(sizeof(node));   
    p->data=c;  
    if(head == NULL)  
    {  
        head = p;  
        head->next = p;  
    }  
    else  
    {  
        p->next = head->next;  
        head->next = p;  
        head = p;  
    }  
}  
  
void delate()  
{  
    if (head == NULL)  
    {  
          
    }else if (head->next == head)  
    {  
        p = head;  
        head = NULL;  
      
    }else{  
        p = head->next;  
        head->next = p->next;  
          
    }  
  
    p = NULL;  
      
}  
  
void move()  
{  
    if(head!=NULL)  
    {  
        head = head->next;  
    }  
}  
  
int main()  
{  
      
    int steps,option,count = 0;  
    char S[100];  
    scanf("%d",&steps);  
    scanf("%s",&S);  
    creat(S);  
      
    while(count < steps)           
    {  
        scanf("%d",&option);          
        switch(option)  
        {  
            case 1:add();break;           
            case 2:delate();break;              
            case 3:move();break;         
        }  
        count++;       
    }  
    p = head;  
    printf("%c",p->data);  
    p=p->next;  
    while(p!=head)  
    {  
        printf("%c",p->data);  
        p=p->next;  
    }  
    printf("\n");  
  
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值