zoukankan      html  css  js  c++  java
  • 005 -- DuLinkList_add nodes, delete node, Caser print..

    000-- define a Dulinklist

    A empty DuLinklist:

    typedef struct DualNode{
        ElemType data;
        struct DualNode *prior;
        struct DualNode *next;
        
    }DualNode, *DuLinkList;

    •  Add a new Node

    s->next = p;    
    s->prior = p->prior;    
    p->prior->next = s;    
    p->prior = s;
    • Delete a Node

    p->prior->next = p->next;
    p->next->prior = p->prior;    
    free(p);

     print A-Z with the defined sequence by user

    e.g.  user input 3

    then should be DEFG....ZABC

    user input -3

    then should be XYZABCEFG.....W

    #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 = 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; 
            p->next = q;
            p=q;
        }
        
        p->next = (*L)->next; //the last Node points to the first Node
        (*L)->next->prior = p; //set the first Node with data 'A' as head Node
        
        return OK;
    }
    
    
    void caser(DuLinkList *L, int i)
    {
        if(i>0)
        {
            do{
                (*L) = (*L)->next;
            } while(--i);
        }
        
        if(i>0)
        {
            i = i-1;
            (*L)=(*L)->next;
            
            do{
                (*L) = (*L)->prior;
                
            }while (++i);
            
        }
        
    }
    
    int main()
    {
        DuLinkList L;
        int i n;
        InitList(&L);
        printf("Please input a integer: 
    ");
        scanf("%d", &n);
        printf("
    ");
        
        caser(&L,n);
        
        for(i=0;i<26;i++)
        {
            L = L->next;
            printf("%c", L->data);
            
        }
        
        printf("
    ");
        
        return 0;
    }
  • 相关阅读:
    mysql prepare语句使用
    mysql 存储过程中的declare 和 set @的两种变量的区别
    Redis命令总结
    系统架构师
    php 大数组的POST问题解决
    ubuntu设置系统时间与网络时间同步
    JAVA开发者最常去的20个英文网站
    文件上传之一句话木马原理及制作
    Postman怎么进行参数化
    单元测试、接口测试、功能测试的区别
  • 原文地址:https://www.cnblogs.com/Shareishappy/p/7545169.html
Copyright © 2011-2022 走看看