[ create a new paste ] login | about

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

C, pasted on Dec 12:
#include<stdio.h>
#include<stdlib.h>

struct node 
  {int info1,info2,info3,info4, info5 ;struct node *left, *right; };
  

struct node Z={ 0,0,0,0,0, &Z, &Z},
 
	y={ 4,11, 5,5,3,&Z, &Z},

	x={ 4,12, 4,6,6,&Z, &Z},

	w={ 4,10, 8,5,3,&Z, &Z},

	vv={ 4,1, 5,5,2,&Z, &Z},

	u={ 4,9, 6,4,5,&Z, &Z},

	tt={ 2,0,0,0,0,&x, &y},

	ss={ 4,5, 3,5,9,&Z, &Z},

	r={ 2,1, 0,0,0,&vv, &w},

	q={ 4,6,2,6,3, &Z, &Z},

	p={ 4,3, 6,4,8,&Z, &Z},

	o={ 1,10,0,0,0, &tt, &u},

	n={ 4,8, 9,2,5,&Z, &Z},

	m={ 1,9, 0,0,0,&r, &ss},
            
	l={ 3,8,0,0,0, &p, &q},
            
	k={ 4,4,6,7,2, &Z, &Z},
            
	j={ 1,7,0,0,0, &n, &o},
            
	i={ 4,2, 1,2,1,&Z, &Z},
                        
	h={ 4,7, 7,5,6,&Z, &Z},

	g={ 3,6,0,0,0, &l, &m},

	f={ 4,13,9,3,4,&Z, &Z},

	e={ 3,5,0,0,0, &j, &k},

	d={ 3,4,0,0,0, &h, &i},

	c={ 2,3,0,0,0, &f, &g},

	bb={ 2,2,0,0,0, &d, &e}, 

	aa={ 3,1,0,0,0, &bb, &c};


/*後順走査*/
struct node postorder(struct node *t){

	struct node *a=&Z,*b=&Z;
	
	if((t->info1>0)&&(t->info1<4)){
	//	printf("1 ");
		*a=postorder(t->left);
		*b=postorder(t->right);

		//info3は足し算、info4,info5は大きいほうを選択
		if(t->info1==1){
			t->info3=a->info3+b->info3;
			
			if(a->info4>b->info4){
				t->info4=a->info4;
			}
			else t->info4=b->info4;
			
			if(a->info5>b->info5){
				t->info5=a->info5;
			}
			else t->info5=b->info5;
		
		}	

		//縦に配置 info4は足し算、info3,info5は大きいほうを選択
 		else if(t->info1==2){
			if(a->info3>b->info3){
				t->info3=a->info3;
			}
			else t->info3=b->info3;
			
			t->info4=a->info4+b->info4;
			
			
			if(a->info5>b->info5){
				t->info5=a->info5;
			}
			else t->info5=b->info5;
		}

		//上下に配置 info5は足し算、info3,info4は大きいほうを選択
		else if(t->info1==3){
			if(a->info3>b->info3){
				t->info3=a->info3;
			}
			else t->info3=b->info3;
			
			if(a->info4>b->info4){
				t->info4=a->info4;
			}
			else t->info4=b->info4;
			
			t->info5=a->info5+b->info5;
		}		
 	
 	printf("info1=%2d, info2=%2d, x=%2d, y=%2d, z=%2d \n",  t->info1,t->info2, t->info3,t->info4,t->info5);
 	return *t;
 	}
 	
 	else{
		printf("info1=%2d, info2=%2d, x=%2d, y=%2d, z=%2d \n",  t->info1,t->info2, t->info3,t->info4,t->info5);
 		return *t;
 	}
}

/*----------------------------------------------------------------------------*/
main()
{
   printf("スタート\n");
   postorder(&tt);
   printf("エンド\n");

}


Output:
1
2
3
4
5
6
7
スタート
info1= 4, info2=12, x= 4, y= 6, z= 6 
info1= 4, info2=11, x= 5, y= 5, z= 3 
info1= 2, info2= 0, x= 5, y=10, z= 3 
エンド

Exited: ExitFailure 10


Create a new paste based on this one


Comments: