zoukankan      html  css  js  c++  java
  • 基础 链表 20117月版本 创建 、删除、插入

    // basic_node.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"

        //随便:50line little bug
    struct node{
        struct node *next;
        int data;
    }Node;

    Node* node_create(){
        Node *head,*pN,*p;    //*p0;
        head=(Node*)malloc(sizeof(Node));    //no doubt sizeof(Node)
        int num;
        p=head->next;
        pN=null;

        while(    1 == scanf("%d",&num) ){
                //bug...no input ,but still have p;
            pN=(Node*)malloc(sizeof(Node));
            pN->data=num;

            pN->next=p;
            p=pN;
        }
            //bug..首节点,没有data
        return head;

    }

    void Node_insert(Node * head,int num){
            //...assert..
        Node *p,*p0,*pN;
        p=head->next;
        //0..new
        pN=(Node*) malloc(sizeof(Node));

        //1..find
        while( p->data <num && p->next != null){
            p0=p;p=p->next;
        }

        //2..judge
        if( p->data >=num){
                //2.1head
            if(p == head->next){
            pN->next=head->next;
            head->next=pN;
            }
                //2.2mid
            pN->next=p;
            p0->next=pN;
        }
                //2.3end
            pN->next=null;
            p->next=pN;
            return 0;
    }//end

    void Node_print(Node *head){
        Node *p,*pp;
        p=head->next;
        //..assert p

        while( p->next!=null){
            printf("%d\n",p->num);
        }

    }
    //dw assert null?
    //..todo del;
    //..todo print,
    //..    todo reverse
        //..    insert data not only;
        //..print 不限

    int _tmain(int argc, _TCHAR* argv[])
    {
        Node* head;
        head=Node_create();
                  Node_insert(head,1);
                  Node_insert(head,-1);
                  Node_print(head);

        return 0;
    }

  • 相关阅读:
    uva 1511 最小生成树
    百度之星2017初赛A-1006-度度熊的01世界
    工作5年总结-总结这两年在阳光的日子
    在visual studio中查看源代码
    根据C#编程经验思考编程核心
    项目的可维护可持续性思考
    java学习
    What is ASP.NET SignalR
    WCF 和 ASP.NET Web API
    wcf服务
  • 原文地址:https://www.cnblogs.com/titer1/p/2316003.html
Copyright © 2011-2022 走看看