示例#1
0
void 
balanceleft (avltree ** n, short adjust)
{
  short dif;

  dif = difference ((*n)->left);
  if (dif == 0)
    {
      rotateright (n);		/* both subtrees of left child of n have same height */
      ((*n)->height) -= adjust;	/* 'decrease' height of current node */
      ((*n)->right->height) += adjust;	/* 'increase' height of right subtree */
    }
  else
    {
      if (dif > 0)
	{
	  rotateright (n);	/* left subtree of left child of n is higher */
	  (*n)->right->height -= 2;
	}
      else
	{			/* right subtree of left child of n is higher */
	  rotateleft (&(*n)->left);	/* pointer to n->left */
	  rotateright (n);
	  ++((*n)->height);	/* increase height of current node */
	  (*n)->right->height -= 2;
	  --((*n)->left->height);	/* decrease height of left subtree */
	}
    }
}
示例#2
0
文件: rbtree.c 项目: linuxbox2/ntirpc
static void insert_recolour(struct opr_rbtree *head,
			    struct opr_rbtree_node *node)
{
	struct opr_rbtree_node *parent, *gramps;

	while ((parent = node->parent) && parent->red) {
		gramps = parent->parent;

		if (parent == gramps->left) {
			struct opr_rbtree_node *uncle = gramps->right;

			if (uncle && uncle->red) {
				uncle->red = 0;
				parent->red = 0;
				gramps->red = 1;
				node = gramps;
				continue;
			}

			if (parent->right == node) {
				rotateleft(head, parent);
				swapnode(&parent, &node);
			}

			parent->red = 0;
			gramps->red = 1;
			rotateright(head, gramps);
		} else {
			struct opr_rbtree_node *uncle = gramps->left;

			if (uncle && uncle->red) {
				uncle->red = 0;
				parent->red = 0;
				gramps->red = 1;
				node = gramps;
				continue;
			}

			if (parent->left == node) {
				rotateright(head, parent);
				swapnode(&parent, &node);
			}

			parent->red = 0;
			gramps->red = 1;
			rotateleft(head, gramps);
		}
	}

	head->root->red = 0;
}
示例#3
0
int read_header(FILE *f){
   int read=fread(header_buf,1,0x300,f);
   int i,j;
   char c;
   char blm[0x10]={0x45,0x45,0x42,0x42,0x4B,0x42,0x4C,0x4D,0x88,0x95,0xA8,0xB1,0x00,0x00,0x00,0x01};
   char bmd[0x10]={0x45,0x45,0x42,0x42,0x4B,0x42,0x4D,0x44,0x20,0x04,0x04,0x26,0x00,0x00,0x00,0x01};
   if(strncmp(header_buf,blm,0x10)==0){
      run_len_array=run_len_array_blm;
      xor_chars_array=xor_chars_array_blm;
      lrc_offs=0x40;
      fprintf(stderr,"INFO: Type BLM.\n");
   }
   else if(strncmp(header_buf,bmd,0x10)==0){
      run_len_array=run_len_array_bmd;
      xor_chars_array=xor_chars_array_bmd;
      lrc_offs=0x220;
      fprintf(stderr,"INFO: Type BMD.\n");
   }
   else{
      fprintf(stderr,"ERR: Wrong file tag!\n");
      return 0;
   }
   strncpy(title,header_buf+0x18,0x20);
   lrc_len=header_buf[0x10]+(header_buf[0x11]<<8)+(header_buf[0x12]<<16)+(header_buf[0x13]<<24);
   dat_len=header_buf[0x14]+(header_buf[0x15]<<8)+(header_buf[0x16]<<16)+(header_buf[0x17]<<24);
   dat_offs=lrc_len+lrc_offs;
   fprintf(stderr,"INFO: LRC len: %d; DAT len: %d.\n",lrc_len,dat_len);
   i=0;
   while(i<8){
      c=title[i*2+1];
      title[i*2+1]=title[i*2+17];
      title[i*2+17]=c;
      i++;
   }
   unsigned char title_keys[4];
   memcpy(title_keys,header_buf+0x14,4);
   title_keys[2]^=header_buf[0x11];
   title_keys[3]^=header_buf[0x10];
   rotateright(title_keys);
   rotateright(title_keys);
   rotateright(title_keys);
   i=0;
   j=0;
   while(i<0x20){
      title[i]^=title_keys[j];
      j=(j+1)%4;
      i++;
   }
   return 1;
}
示例#4
0
文件: avl.c 项目: ivanria/bin_trees
tree_t *balance(tree_t *p)
{
	fixheight(p);
	if (bfactor(p) == 2) {
		if (bfactor(p->right) < 0)
			p->right = rotateright(p->right);
		return rotateleft(p);
	}
	if (bfactor(p) == -2) {
		if (bfactor(p->left) > 0)
			p->left = rotateleft(p->left);
		return rotateright(p);
	}
	return p;
}
示例#5
0
文件: main.c 项目: Alecs94/DSA-lab
node * LL(node *T)
{
               T=rotateright(T);
               printf("after the right rotation : \n");
               prettyPrint(T,0);
               return(T);
}
示例#6
0
文件: main.c 项目: Alecs94/DSA-lab
node * LR(node *T)
{
               T->left=rotateleft(T->left);
               printf("after the left rotation : \n");
               prettyPrint(T,0);
               T=rotateright(T);
               printf("after the right rotation : \n");
               prettyPrint(T,0);
               return(T);
}
示例#7
0
文件: clutil.c 项目: Azimbek/ITEE-UQ
/* generates a move according to the walling algorithm
Three cases (agent is at > moving east:
  #.
   >      Rotate left
   
  #
  >       Move ahead
  
  
  
  .       
  >       Move ahead
*/   
void wallmove(clientinfo_t* client, int* dr, int* dc) {
    char backleft=backleftcorner(client, *dr, *dc);
    char left=leftchar(client, *dr, *dc);
    if ((backleft=='#') && (left==' ')) {
      
// printf("Triggered left turn\n");
// fflush(stdout);
	rotateright(dr, dc);
	rotateright(dr, dc);	// lazy left turn
	rotateright(dr, dc);
	// now either this is clear or blocked by agent
	if (blockedbyagent(client, *dr, *dc)) {
	    printf("H\n");
	    fflush(stdout);
	    return;
	}
	// not blocked so move forward
	printf("%c\n", fwdmove(*dr, *dc));
	fflush(stdout);
	return;
    }
    for (int i=0;i<4;++i) {
        if ((fwdchar(client, *dr, *dc)==' ')) {
	    if (blockedbyagent(client, *dr, *dc)) {
	        printf("H\n");
		fflush(stdout);
		return;
	    }
	    	    // not blocked so move forward
	    printf("%c\n", fwdmove(*dr, *dc));
	    fflush(stdout);
	    return;
	}
	// we must be blocked fwd so rotate and try again
	rotateright(dr, dc);
    }	
    // if we get here, we must be surrounded
    printf("H\n");
    fflush(stdout);
}
示例#8
0
void rotate90right()
{
	start_request = 1;
	TransmitComm(update);
	for(long i = 0; i < 80000; i ++)
	{
		stopp();
	}

	storedValues[6] = 0;
	while(turnisDone == 0)
	{
		start_request = 1;
		TransmitSensor(turn);
		if (storedValues[6] != 2)
		{
			rotateright();
		}
		else
		{
			start_request = 1;
			TransmitSensor(turnstop);
			stopp();
			turnisDone = 1;
		}
	}
	if(mydirection == 1)
	{
		mydirection = 4;
	}
	else
	{
		mydirection -= 1;
	}
	turnisDone = 0;
	storedValues[8] = mydirection;

	for(long i = 0; i < 80000; i ++)
	{
		stopp();
	}

	start_request = 1;
	TransmitSensor(0);
	TransmitComm(update);
	posdistance = 0;
	n = 0;
}
示例#9
0
文件: main.cpp 项目: process/euler
int main()
{
	getprimes();

	int i, temp, count = 0;
	for(i = 0; Primes[i]; i++)
	{
		temp = Primes[i];
		do
		{
			if(!isprime(temp = rotateright(temp)))
				break;
		}while (temp != Primes[i]);

		if(temp == Primes[i])
			count++;
	}

	printf("%d\n", count);

	return 0;
}
示例#10
0
node * RL(node *T)
{
               T->right=rotateright(T->right);
               T=rotateleft(T);
               return(T);
}
示例#11
0
node * LR(node *T)
{
               T->left=rotateleft(T->left);
               T=rotateright(T);
               return(T);
}
示例#12
0
node * LL(node *T)
{
               T=rotateright(T);
               return(T);
}
示例#13
0
文件: rbtree.c 项目: linuxbox2/ntirpc
static void remove_recolour(struct opr_rbtree *head,
			    struct opr_rbtree_node *parent,
			    struct opr_rbtree_node *node)
{
	struct opr_rbtree_node *other;

	while ((node == NULL || !node->red) && node != head->root) {
		if (parent->left == node) {
			other = parent->right;
			if (other->red) {
				other->red = 0;
				parent->red = 1;
				rotateleft(head, parent);
				other = parent->right;
			}
			if ((other->left == NULL || !other->left->red)
			    && (other->right == NULL || !other->right->red)) {
				other->red = 1;
				node = parent;
				parent = node->parent;
			} else {
				if ((other->right == NULL) ||
				    (!other->right->red)) {
					other->left->red = 0;
					other->red = 1;
					rotateright(head, other);
					other = parent->right;
				}
				other->red = parent->red;
				parent->red = 0;
				other->right->red = 0;
				rotateleft(head, parent);
				node = head->root;
				break;
			}
		} else {
			other = parent->left;
			if (other->red) {
				other->red = 0;
				parent->red = 1;
				rotateright(head, parent);
				other = parent->left;
			}
			if ((other->left == NULL || !other->left->red)
			    && (other->right == NULL || !other->right->red)) {
				other->red = 1;
				node = parent;
				parent = node->parent;
			} else {
				if (other->left == NULL || !other->left->red) {
					other->right->red = 0;
					other->red = 1;
					rotateleft(head, other);
					other = parent->left;
				}
				other->red = parent->red;
				parent->red = 0;
				other->left->red = 0;
				rotateright(head, parent);
				node = head->root;
				break;
			}
		}
	}
	if (node)
		node->red = 0;
}
AVLTree_Node * RL(AVLTree_Node *T)
{
    T->right=rotateright(T->right);
    T=rotateleft(T);
    return(T);
}
AVLTree_Node * LR(AVLTree_Node *T)
{
    T->left=rotateleft(T->left);
    T=rotateright(T);
    return(T);
}
AVLTree_Node * LL(AVLTree_Node *T)
{
    T=rotateright(T);
    return(T);
}
示例#17
0
文件: twosides.c 项目: andersas/C
int twosides (float a, float b, float c, float A, float B, float C) {

int rotation = 0; /* always rotate LEFT, and unrotate RIGHT */
float tmp;
int solutions = 0;

if (A) rotation = 0;
if (B) rotation = 1;
if (C) rotation = 2;

rotateleft(&a, &b, &c, &A, &B, &C, rotation);


	if (a && b) {
		/* a/sin(A)=b/sin(B) */
		B = (b*sin(A))/a;
		if (B > 1 || B < -1) goto FAILURE;
		B = asin(B);
		tmp = B;
		if (deg2rad(180)-B+A < deg2rad(180)) {
			/* two solutions */
			solutions++;

			B = deg2rad(180) - B;
			C = deg2rad(180-rad2deg(A)-rad2deg(B));
			c = a*sin(C)/sin(A);
			rotateright(&a, &b, &c, &A, &B, &C, rotation);
			solution(a,b,c,A,B,C,solutions);
			rotateleft(&a, &b, &c, &A, &B, &C, rotation);
			solutions++;
		}
		B = tmp;
		C = deg2rad(180-rad2deg(A)-rad2deg(B));
		c = a*sin(C)/sin(A);
		rotateright(&a, &b, &c, &A, &B, &C, rotation);
		solution(a,b,c,A,B,C,solutions);
		rotateleft(&a, &b, &c, &A, &B, &C, rotation);
		
		return 0;
	}

	if (a && c) {
		/* a/sin(A)=c/sin(C) */
		C = (c*sin(A))/a;
		if (C > 1 || C < -1) goto FAILURE;
		C = asin(C);
		tmp = C;
		if (deg2rad(180)-C+A < deg2rad(180)) {
			/* two solutions*/
			solutions++;

			C = deg2rad(180) - C;
			B = deg2rad(180-rad2deg(A)-rad2deg(C));
			b=a*sin(B)/sin(A);
			rotateright(&a, &b, &c, &A, &B, &C, rotation);
			solution(a,b,c,A,B,C,solutions);
			rotateleft(&a, &b, &c, &A, &B, &C, rotation);
			solutions++;
		}
		C = tmp;
		B = deg2rad(180-rad2deg(A)-rad2deg(C));
		b = a*sin(B)/sin(A);
		rotateright(&a, &b, &c, &A, &B, &C, rotation);
		solution(a,b,c,A,B,C,solutions);
		rotateleft(&a, &b, &c, &A, &B, &C, rotation);
		
		return 0;
	}

	if (b && c) {
		/* a^2 = b^2+c^2-2bc*cos(A) */
		a = sqrt(pow(b,2)+pow(c,2)-2*b*c*cos(A));
		B = (pow(a,2) + pow(c,2) - pow(b,2)) / (2*a*c);
		if (B > 1 || B < -1) goto FAILURE;
		B = acos(B);
		C = deg2rad(180) - A - B;

		rotateright(&a, &b, &c, &A, &B, &C, rotation);
		solution(a,b,c,A,B,C,solutions);
		rotateleft(&a, &b, &c, &A, &B, &C, rotation);
		return 0;
	}


FAILURE:
printf("Impossible triangle!\n");
return 1;

}