[ create a new paste ] login | about

Link: http://codepad.org/7S2qtvXw    [ raw code | output | fork ]

C++, pasted on Jun 28:
#include <iostream>
#define null 0 



struct node{
		
		int data;
		node *R;
		node *L;
};

void SS(node *p){
	
	

	
	
	if(p!=0){
	
		SS(p->L) ; 
		printf("%d\n",p->data) ; 
		SS(p->R) ; 
	} 
	


} 
 



int main(int argc, char** argv) {
	
	int x[]={5,3,9,1,6,4,8,2,7};

	
	node *root=new node(),*p=root;
	
	
	
	
//	*p=*root;
	root->data=x[0];
	root->L=null;
	root->R=null;
	
 	for(int i=1;i<=8;i++){
  	int zz=1;	
	 p=root; 
	 	

//	bool star=ture; 	 
	 	while(zz=1){
	 	
	 		if(x[i]>p->data){
	 			
	 			if(p->R==null){
	 				p->R=new node();
	 				zz=0;
	 			}
	 			p=p->R;
	 			  
			}
			else{
				
				if(p->L==null){
					
					p->L=new node();
					zz=0;
				
				}
					p=p->L;
			}
				
	 	}
 		p->data=x[i]	; 
 		
 	}

	printf("中序\n");
	 
	SS(root) ; 
	
	
	return 0;
}


Output:
1
2
3
cc1plus: warnings being treated as errors
In function 'int main(int, char**)':
Line 54: warning: suggest parentheses around assignment used as truth value


Create a new paste based on this one


Comments: