// 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;
}