• double links....baoyuzuoye


    这里写图片描述

    #include<cstdio>//cww double links
    #include<iostream>
    using namespace std;
    struct node{
        int data;
        node *next;
        node *last;
        node(){int data=0;node *next=NULL;node *last=NULL;}
    }*head,*rear;
    
    void append(int x){//push_back
        node* p=new node;
        p->data=x;//fill in the number
        p->last=rear->last;
        p->last->next=p;
        rear->last=p;
        p->next=rear;//该链的链上 
    }
    //===============orders=====================
    void build(){
        head=new node;
        rear=new node;
        head->next=rear;
        rear->last=head;
        //now the links is empty 
        printf("How many numbers at the beginning:");
        int n,x;scanf("%d",&n);
        for (;n--;){
            scanf("%d",&x);
            append(x);//push_back
        }
    }
    node* Find(node* head,int x){//find.....
        node *p=head->next;
        for (;p!=NULL;p=p->next){
            if (p->data==x)return p;
        }//just find ,nothing else
        return NULL;
    }
    //===============get order====================
    char getorder(){//获取指令 
        while (1){
            printf("Select command and press<Enter>:");
            char ch; cin>>ch;
            if (ch=='f'||ch=='b'||ch=='q'||ch=='Q')return ch;
            //ps:it's not a bad idea to add more fuctions
            //such as insert....I'm lazy
            puts("Please enter a valid command  :");
            puts("[b]build a new double link  = =");
            puts("[f]find x in the link you built");
            puts("[Q]uit =======Bazinga!=========");
        }//交互式的程序好烦 
    }
    //===============main=fuction===============
    bool solve(char ch){
        if (ch=='q'||ch=='Q')return 0;//quit
        if (ch=='b'){build();}//creat a new links
        if (ch=='f'){//find 
            printf("Tell me what you want to find:");
            int x;scanf("%d",&x);
            node *p=new node;
            p=Find(head,x); //find x 
            if (p=NULL)puts("Nowhere to be found");
            else printf("%x
    ",&p);//question:print what?
        }
        return 1;
    }
    //============cww=2016=3=22=22:17=============
    int main(){
        while (solve(getorder())){}
        return 0;
    }
  • 相关阅读:
    登录注册数据库建立
    AngularJS学习小结
    响应布局
    JQuery内容从左边框移到右边框
    Jquery图片轮播和CSS图片轮播
    Bootstrap栅格系统
    用Javascript大批量收集网站数据
    如何用CSS快速布局(一)—— 布局元素详细
    怎么应用vertical-align,才能生效?
    line-height系列(二)——对行内元素(文字、图片、兄弟元素)、块级元素设置line-height后的表现
  • 原文地址:https://www.cnblogs.com/cww97/p/7534009.html
Copyright © 2020-2023  润新知