输入1,则跳过第一个从第二个开始输出,输入-1,则把最后一个放在最前面,然后开始输出。。。
#define LIST "ABCDEFGHIJKLMNOPQRSTUVWXYZ" typedef struct DulNode { char data; struct DulNode *prior; struct DulNode *next; }DulNode; void circle_init(DulNode *head); void circle_print(DulNode *head, const int startNum); void circle_des(DulNode *head); int main() { DulNode head = {'0', &head, &head}; int start = 0; circle_init(&head); circle_print(&head, start); printf("输入跳过字符数量:"); scanf("%d", &start); circle_print(&head, start); circle_des(&head); return 0; } void circle_init(DulNode *head) { DulNode *p = head; int len = strlen(LIST); int i = 0; for(i=0; i<len; i++) { p->next = (DulNode *)malloc(sizeof(DulNode)); p->next->next = head->prior; p->next->prior = p; head->prior = p->next; p = p->next; p->data = LIST[i]; } p->next = head->next; head->next->prior = p; } void circle_print(DulNode *head, const int startNum) { DulNode *p = head->next; DulNode *start = NULL; int i = startNum; if(i>0) { while(i) { p = p->next; i--; } }else { while(i) { p = p->prior; i++; } } start = p; do { printf("%c ", p->data); p = p->next; }while(p != start); printf(" "); } void circle_des(DulNode *head) { DulNode *p = head->next; DulNode *q = NULL; do { q = p->next; free(p); p = q; }while(p != head->next); head->next = head; head->prior = head; }
后来才知道,其实不用定义一个全局的字符串,可以直接用ASCII码赋值,即‘A’+1,即可得到'B'。。。。。。