• 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;
    }
  • 相关阅读:
    单/多文档的窗体类属性修改(VC_MFC)
    RTTI 与消息机制(VC_MFC)
    对话框属性页(VC_MFC)
    插入符与路径(VC_MFC)
    重画控件与系统托盘图标编写(VC_MFC)
    颜色,文件和字体对话框(VC_MFC)
    ODBC 数据类型和API(VC)
    CTreeCtrl 和 CListCtrl 控件(VC_MFC)
    找回桌面清理向导清理多余IE图标
    win7任务栏缩略图消失的解决方法
  • 原文地址:https://www.cnblogs.com/Shareishappy/p/7545169.html
Copyright © 2020-2023  润新知