zoukankan      html  css  js  c++  java
  • list

    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    typedef struct ListNode{
    	int data;
    	ListNode* pre;
    	ListNode* nxt;
    }List;
    int length;
    
    List* CreateList(int len)
    {
    	List* ret=(List*)malloc(sizeof(List));
    	List* tail=ret;
    	ret->pre=ret,ret->nxt=ret,ret->data=1;
    	for(int i=2;i<=len;i++)
    	{
    		List* newnode=(List*)malloc(sizeof(List));
    		newnode->data=i,
    		tail->nxt=newnode,newnode->pre=tail,newnode->nxt=ret,tail=newnode;
    	}
    	ret->pre=tail;
    	length=len;
    	return ret;
    }
    void Delete(List* pos)
    {
    	pos->pre->nxt=pos->pre;
    	pos->nxt->pre=pos->nxt;
    	free(pos);
    	length--;
    }
    List* JumpToItem(List* list,int n)
    {
    	if(n==0) return list;
    	while(n--)
    		list=list->nxt;
    	return list;
    }
    void Print(List* list)
    {
    	printf("%d ",list->data);
    	for(int i=2;i<=length;i++)
    	{
    		list=list->nxt;
    		printf("%d ",list->data);
    	}
    	printf("
    ");
    }
    void InsertAft(List* pos,int data)
    {
    	List* newnode=(List*)malloc(sizeof(newnode));
    	newnode->data=data,
    	newnode->pre=pos,newnode->nxt=pos->nxt,pos->nxt=newnode;
    	length++;
    }
    void InsertBef(List* pos,int data)
    {
    	pos=pos->pre;
    	InsertAft(pos,data);
    }
    int main()
    {
    	List* list=CreateList(15);
    	Print(list);
    	Delete(list);
    	Print(JumpToItem(list,1));
    	InsertAft(list,233);
    	Print(JumpToItem(list,1));
    	InsertBef(JumpToItem(list,2),2333);
    	Print(JumpToItem(list,1));
    	return 0;
    }
    

      

    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    typedef struct ListNode{
        ListNode* pre;
        ListNode* nxt;
        int data;
    }List;
    int length;
    List* head;
    List* tail;
    inline List* CreateList(int len)
    {
        length=len;
        List* ret=(List*)malloc(sizeof(List));
        ret->data=1;
        head=ret,tail=ret;
        for(int i=2;i<=len;i++)
        {
            List* newnode=(List*)malloc(sizeof(List));
            newnode->data=i,newnode->nxt=head,tail->nxt=newnode,newnode->pre=tail,tail=newnode;
        }
        ret->pre=tail;
        return ret;
    }
    inline void Print()
    {
        int len=length;
        List* node=head;
        while(len--)
        {
            printf("node: %d, pre: %d, nxt: %d, data: %d
    ",node,node->pre,node->nxt,node->data);
            node=node->nxt;
        }
    }
    inline List* JumpToItem(int pos)
    {
        List* ret=head;
        while(pos--)ret=ret->nxt;
        return ret;
    }
    inline void Delete(List* elem)
    {
        elem->pre->nxt=elem->nxt;
        elem->nxt->pre=elem->pre;
        if(elem==head)head=elem->nxt;
        if(elem==tail)tail=elem->pre;
        length--;
        free(elem);
    }
    inline void InsertAft(List* pos,int data)
    {
        List* newnode=(List*)malloc(sizeof(List));
        newnode->data=data;
        newnode->pre=pos,newnode->nxt=pos->nxt;
        pos->nxt=newnode,pos->nxt->pre=newnode;
        if(pos==tail)tail=newnode;
        length++;
    }
    inline void InsertBef(List* pos,int data)
    {
        List* newnode=(List*)malloc(sizeof(List));
        InsertAft(pos->pre,data);
        if(newnode==head)head=newnode;
    }
    int main()
    {
        List* list=CreateList(20);
        Print();
        InsertBef(list,2333);
        Print();
    }
    #include<cstdio>
    #include<cstdlib>
    #include<windows.h>
    using namespace std;
    struct Linker
    {
        typedef struct ListNode
        {
            ListNode* pre;
            ListNode* nxt;
            int data;
        } List;
        int length;
        List* head;
        List* tail;
        inline void CreateList(int len)
        {
            length=len;
            List* ret=(List*)malloc(sizeof(List));
    		ret->data=1;
            head=ret,tail=ret;
            for(int i=2; i<=len; i++)
            {
                List* newnode=(List*)malloc(sizeof(List));
                newnode->data=i,newnode->nxt=head,tail->nxt=newnode,newnode->pre=tail,tail=newnode;
            }
            ret->pre=tail;
        }
        inline void Print()
        {
            int len=length;
            List* node=head;
            while(len--)
            {
                printf("node: %d, pre: %d, nxt: %d, data: %d
    ",node,node->pre,node->nxt,node->data);
                node=node->nxt;
            }
        }
        inline List* JumpToItem(int pos)
        {
            List* ret=head;
            while(pos--)ret=ret->nxt;
            return ret;
        }
        inline void Delete(List* elem)
        {
            elem->pre->nxt=elem->nxt;
            elem->nxt->pre=elem->pre;
            if(elem==head)head=elem->nxt;
            if(elem==tail)tail=elem->pre;
            length--;
            free(elem);
        }
        inline void InsertAft(List* pos,int data)
        {
            List* newnode=(List*)malloc(sizeof(List));
            newnode->data=data;
            newnode->pre=pos,newnode->nxt=pos->nxt;
            pos->nxt=newnode,pos->nxt->pre=newnode;
            if(pos==tail)tail=newnode;
            length++;
        }
        inline void InsertBef(List* pos,int data)
        {
            List* newnode=(List*)malloc(sizeof(List));
            newnode->data=data;
            newnode->pre=pos->pre,newnode->nxt=pos;
            pos->pre=newnode,newnode->pre->nxt=newnode;
            if(pos==head)head=newnode;
            length++;
        }
    };
    Linker List;
    int main()
    {
        List.CreateList(1000000);//25M. 
        return 0;
    }
    

      

  • 相关阅读:
    A Simple Problem with Integers poj 3468 多树状数组解决区间修改问题。
    Fliptile 开关问题 poj 3279
    Face The Right Way 一道不错的尺取法和标记法题目。 poj 3276
    Aggressive cows 二分不仅仅是查找
    Cable master(二分题 注意精度)
    B. Pasha and String
    Intervals poj 1201 差分约束系统
    UITextField的快速基本使用代码块
    将UIImage转换成圆形图片image
    color转成image对象
  • 原文地址:https://www.cnblogs.com/TheRoadToAu/p/8012755.html
Copyright © 2011-2022 走看看