#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");
}
循环链表
最新推荐文章于 2017-09-06 20:53:51 发布