Small code linked list realization Lights out Game 2

Source: Internet
Author: User

/*cout <<  " *****************game by  ring light********************* " << endl;    cout << "  ****  a full-cycle series lamp chain     for saving resources wait for your turn off the light action ****** " << endl;    cout <<   " ***** tip:  when a lamp is selected, the lamp and the lamp state next to it will change."  << endl;    cout  <<  " *****************game by  ring light**************************"  << endl;     the solution is simply to switch from the first point of all the lights can be achieved all the lights from full-light to all-out */   #include  <iostream>using namespace std;struct node{int data;node *prev;node * Next;public:node ():d ATA (1), prev (null), Next (null) {}node (int a):d ATA (a), prev (null), Next (null) {}}; void  creat (node *list) {int n=20;node *tmp;node *tail;while (n--) {if (list->next ==  null) {TMP&NBSP;&NBsp;= new node (1); tmp->prev = list;tmp->next = list;list->prev =  tmp;list->next = tmp;tail=tmp;} Else{tmp = new node (1); list->next->prev = tmp;tmp->next = list- >next;tmp->prev = tail;tail->next=tmp;list->next = tmp;}}} Void show (node *list) {int n=20;node *p = list->next;while (n--) {//cout<< "[" <<20-n<< "] " <<p->data<< " ";cout<<p->data<< " ";p =p- >next;}     cout<<endl;} Void _play (node *list,int x) {         node *p  = list->next;    while (x-- -1)     {         p=p->next;    }    p->prev- >data=1-p->prev->data;    p->data=1-p->data;    p->next->data=1-p->next->data;      }int check (node *list) {     int n=20;node *p  = list->next;while (n--) {     if (p->data==1) Break; p=p->next;}      return 1-p->data;} Void play (node *list) {         int x=1;        int n=40;      while (n--)        {                    cout<< "40 Steps to solve Riddles" <<40-n<< "Step: (Input 0~20)" <<endl<< ' \ t ' << ' t ';          cin>>x;          _play (list,x);      &nbsP; show (list);        if (N==20&&check (list)) break;       }}int main () {          cout  <<  " *****************game by  ring light**************************"  << endl;    cout <<  " ****  a full cycle series lamp chain      waiting for you to save resources to turn off the light action ****** " << endl;    cout << "  ***** tip:  When a lamp is selected, the lights and the lights on the side will change. * * *  << endl;    cout  <<  " *****************game by  ring light**************************"   << endl;    node list;creat (&list),  show (&list);p Lay (& list), show (&list);cout <<  " wzzx"  << endl;return 0;}


Small code linked list realization Lights out Game 2

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.