69,336
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
char c;
struct node *next;
};
typedef struct node *Link;
Link init();
void Delete(Link *L);
void move(Link *L);
void Insert(Link *L,char ch);
void print(Link head);
int main(void){
char ch;
int i;
int playnum;
int choose;
Link L;
scanf("%d", &playnum);
L = init();
for(i=0;i<playnum;i++){
scanf("%d", &choose);
if(choose==1){
scanf(" %c",&ch);
Insert(&L,ch);
}
if(choose==2){
if(!(L->next==L)){
Delete(&L);
}
}
if(choose==3){
L = L->next;
}
}
print(L);
printf("\n");
return 0;
}
Link init(){
Link head;
Link before;
Link newnode;
Link tall;
int i, num;
char str[1000];
//初始字符串的输入
scanf("%s",str);
num = strlen(str);
head = (Link)malloc(sizeof(struct node));
if(!head)
return NULL;
head->c = str[0];
head->next = NULL;
before = head;
//讲初始字符串接入链表
for(i=1;i<num;i++){
newnode = (Link)malloc(sizeof(struct node));
if(!newnode)
return NULL;
newnode->c = str[i];
newnode->next = NULL;
before->next = newnode;
before = newnode;
}
newnode->next = head;
tall = newnode;
return tall;
}
void Insert(Link *L,char ch){
Link p,s;
p = *L;
s = (Link)malloc(sizeof(struct node));
s->c = ch;
//
s->next = p->next;
p->next = s;
//指针后移
p = p->next;
*L = p;
}
void Delete(Link *L){
Link p,q;
p = *L;
q = p->next;
p->next = q->next;
free(q);
*L = p;
}
void print(Link head){
Link p;
p = head;
do
{
printf("%c",p->c);
p = p->next;
}while(head!=p);
}