输入数字后就#include <stdio.h>
#include <stdlib.h>
struct Node{
char s;
struct Node *prior;
struct Node *next;
};
struct Node *gengerate_letter(void);
struct Node *move(struct Node *head, int i);
void print_Node(struct Node *head);
void clerr(struct Node **head);
int main(){
int i;
struct Node *head;
head = gengerate_letter();
printf("请输入移动的距离:");
printf("-----------\n");
scanf("%d", &i);
printf("-----------");
head = move(head, i);
print_Node(head);
clerr(&head);
}
struct Node *gengerate_letter(void){
int i;
struct Node *head = NULL;
struct Node *node, *now;
for (i = 0; i < 26; i++){
now = (struct Node *)malloc(sizeof(struct Node));
if(!now){
exit(0);
}
now->s = 'A' + i;
if (head == NULL){
head = now;
node = head;
}
else{
node->next = now;
now->prior = node;
node = now;
}
}
node->next = head;
head->prior = node;
return head;
}
struct Node *move(struct Node *head, int i){
int a;
struct Node *node;
node = head;
for (a = 0; a != i; ){
if (a < i){
node = node->next;
a++;
}
else{
node = node->prior;
a--;
}
}
return node;
}
void print_Node(struct Node *head){
struct Node *node;
node = head;
while (node->next != head){
printf("%c", node->s);
node = node->next;
}
}
void clerr(struct Node **head){//将单链表清空
struct Node *node, *temp;
node = *head;
while (node->next){
temp = node;
node = node->next;
free(temp);
}
free(node);
}
卡了
|