Two-way cyclic chain list practice

Source: Internet
Author: User

Watch the Little Turtle Video:

Requires a user to enter a number to make 26 letters change, such as input 3 output results:

Defghijklmnopqrstuvwxyzabc

Output-3 Get Results

Xyzabcdefhijklmnopqrstuvw

#include <stdio.h> #include <stdlib.h> #define OK 1 #define ERROR 0 typedef char Elemtype;

typedef int STATUS;
	typedef struct DUALNODE {elemtype data;
	struct Dualnode *prior;
struct Dualnode *next;

}dualnode,*dulinklist;
	Status initlist (dulinklist *l) {Dualnode *p,*q;

	int i;
	*l = (dulinklist) malloc (sizeof (Dualnode)); if (! (
	*l) {return ERROR;

	} (*l)->next = (*l)->prior;//(*L)->next= null:p = (*l);
		for (i=0;i<26;i++) {q = (Dualnode *) malloc (sizeof (Dualnode));
		if (!q) {return ERROR;
		} q->data = ' A ' +i;
		Q->prior = p;
		Q->next = p->next;//equal Q->next = NULL;
		P->next = q;
	p = q;
	} P->next = (*l)->next;

	(*l)->next->prior = p;
return OK;
		} void Caesar (Dulinklist *l,int i) {if (i>0) {do {(*l) = (*l)->next; 
	}while (i.);
		} if (i<0) {do {(*l) = (*l)->next;
	}while (++i);
	}} int main () {dulinklist L;

	int i,n;
	Initlist (&AMP;L); printf ("Enter a numbER: ");

	scanf ("%d", &n);
	
	Caesar (&l,n);
		for (i=0;i<26;i++) {l=l->next;
	printf ("%c", l->data);

	} printf ("\ n");
return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.