コード例 #1
0
ファイル: kdtree.C プロジェクト: gnishida/Geometry4
void KdTreeNode::insert (LineSegment *l)
{
  switch (splitType) {
  case 0:
    if (l->p0 != splitAt && l->p1 != splitAt && XOrder(l->p0, splitAt) == 1 && XOrder(l->p1, splitAt) == 1) {
	  insertLeft(l);
	} else if (l->p0 != splitAt && l->p1 != splitAt && XOrder(splitAt, l->p0) == 1 && XOrder(splitAt, l->p1) == 1) {
	  insertRight(l);
	} else {
	  LineSegment *l0, *l1;
	  splitLineSegment(l, splitAt, splitType, &l0, &l1);

      insertLeft(l0);
	  insertRight(l1);
	}
	break;
  case 1:
    if (l->p0 != splitAt && l->p1 != splitAt && YOrder(l->p0, splitAt) == 1 && YOrder(l->p1, splitAt) == 1) {
	  insertLeft(l);
	} else if (l->p0 != splitAt && l->p1 != splitAt && YOrder(splitAt, l->p0) == 1 && YOrder(splitAt, l->p1) == 1) {
	  insertRight(l);
	} else {
	  LineSegment *l0, *l1;
	  splitLineSegment(l, splitAt, splitType, &l0, &l1);
      insertLeft(l0);
	  insertRight(l1);
	}
    break;
  }
}
コード例 #2
0
ファイル: avl.c プロジェクト: zecarlos94/LI3_GZT
/*Insere um nodo na AVL*/
AVL insert(AVL p,void* unc_info , int *cresceu,int tipo_AVL) {
	
	if(tipo_AVL == Catalogo_C || tipo_AVL == Catalogo_P)
	{
	char* code = (char*)unc_info; 
	if(p==NULL) {
		
		p = (AVL) malloc(sizeof(struct avl_node));
		p->info = malloc(10*sizeof(char));
		strcpy(p->info, code);
		p->right=p->left=NULL;
		p->bf=EH;
		*cresceu=1;
		}
		else {
			char* info = (char*)p->info;
		if(strncmp(code, info, strlen(code))<0) p=insertLeft(p,unc_info, cresceu,tipo_AVL);
	     		else p=insertRight(p,unc_info, cresceu,tipo_AVL);
		}
	}
	else
	{
	Comp compra = (Comp) unc_info;
		if(p==NULL)
		{
		Comp info = (Comp) p->info;
		p = (AVL) malloc(sizeof(struct avl_node));
		p->info = (Comp) malloc(sizeof(struct compras));
		info = p->info;
		info->codigo_produto = malloc(10*sizeof(char));
        	info->codigo_cliente = malloc(10*sizeof(char));
		compracpy(p->info,compra);
		p->right=p->left=NULL;
		p->bf=EH;
		*cresceu=1;
		}
		
		else if(tipo_AVL == Compras_Ord_CP)
		{
			if(compracmpCP(compra,p->info) < 0) p=insertLeft(p,unc_info,cresceu,tipo_AVL);
				else p = insertRight(p,unc_info,cresceu,tipo_AVL);	
			}
		else /* Compras_Ord_CC*/
		{

			if(compracmpCC(compra,p->info) < 0) p=insertLeft(p,unc_info,cresceu,tipo_AVL);
				else p = insertRight(p,unc_info,cresceu,tipo_AVL);	
		}
	
	}

	return p;
}
コード例 #3
0
bool ossimImageChain::addFirst(ossimConnectableObject* obj)
{
   ossimConnectableObject* rightOfThisObj =
      (ossimConnectableObject*)getFirstObject();

   return insertRight(obj, rightOfThisObj);
}
コード例 #4
0
ファイル: b02.c プロジェクト: jcarlosadm/classes
/**
 * Insere nó à direita da última inserção, em uma posição adequada
 * Retorna ponteiro para o nó inserido
 *
 * Node* current: nó atual
 * Node* left: nó à esquerda do nó atual
 * int item: valor a ser inserido
 */
Node* insertRight(Node* current, Node* left, int item){
    if(current==NULL){
        Node* newNode = (Node*)malloc(sizeof(Node));
        if(!newNode)return left;
        
        newNode->item = item;
        newNode->nextNode = NULL;
        newNode->previousNode = left;
        
        left->nextNode = newNode;
        return newNode;
    }
    else if(current->item > item){
        Node* newNode = (Node*)malloc(sizeof(Node));
        if(!newNode)return current;
        
        newNode->item = item;
        newNode->nextNode = current;
        newNode->previousNode = current->previousNode;
        
        current->previousNode->nextNode = newNode;
        current->previousNode = newNode;
        
        return newNode;
    }
    else{
        return insertRight(current->nextNode,current,item);
    }
}
コード例 #5
0
ファイル: createByGenList.c プロジェクト: feng-qi/Workspace
void createByGenList(TNode *root, char *list) {
  TNode *temp;
  char *p;
  int i;
  int level = 0;

  root->left = 0;
  root->right = 0;

  for (p = list; *p == ')' && level == 1; p++) {
    switch(*p) {
      case '(':
	level += 1;
	++p;
	insertLeft(temp, *p);
	break;
      case ',':
	break;
      case ')':
	level -= 1;
	break;
      default:
	if (level == 1) root->data = *p;
	else {
	  temp = root->left;
	  for (i = level; i > 1; i--)
	    temp = temp->left;
	  temp = insertRight(temp, *p);
	}
	break;
    }
  }
}
コード例 #6
0
ファイル: threaded.c プロジェクト: sjlee2016/datastructure
void insert(threadedPointer s, char data)
{
	threadedPointer newNode = (threadedPointer)malloc(sizeof(threadedTree));
	newNode->data = data;
	newNode->leftChild = NULL;
	newNode->rightChild = NULL;
	newNode->leftThread = TRUE;
	newNode->rightThread = TRUE;
	insertRight(s, newNode);

}
コード例 #7
0
bool ossimImageChain::insertRight(ossimConnectableObject* newObj,
                                  const ossimId& id)
{
   ossimConnectableObject* obj = findObject(id, false);
   if(obj)
   {
      return insertRight(newObj, obj);
   }

   return false;
}
コード例 #8
0
ファイル: mach++.cpp プロジェクト: Apple-FOSS-Mirror/Security
//
// ReceivePorts
//
ReceivePort::ReceivePort(const char *name, const Bootstrap &bootstrap, bool tryCheckin /* = true */)
{
	if (tryCheckin)
		mPort = bootstrap.checkInOptional(name);
	if (!mPort) {
		allocate();
		// Bootstrap registration requires a send right to (copy) send.
		// Make a temporary one, send it, then take it away again, to avoid
		// messing up the caller's send right accounting.
		insertRight(MACH_MSG_TYPE_MAKE_SEND);
		bootstrap.registerAs(mPort, name);
		modRefs(MACH_PORT_RIGHT_SEND, -1);
	}
}
コード例 #9
0
ファイル: b02.c プロジェクト: jcarlosadm/classes
/**
 * Insere nó de forma ordenada
 * retorna ponteiro para o nó inserido
 *
 * Node* middle: ponteiro para o nó da última inserção
 *      (não necessariamente presente no meio da lista)
 * int item: valor a ser inserido no novo nó
 */
Node* insertOrderedNode(Node* middle, int item){
    
    if(middle==NULL){
        Node* newNode = (Node*)malloc(sizeof(Node));
        newNode->item = item;
        newNode->nextNode = NULL;
        newNode->previousNode = NULL;
        return newNode;
    }
    else{
        if(middle->item > item){
            return insertLeft(middle->previousNode,middle,item);
        }
        else{
            return insertRight(middle->nextNode,middle,item);
        }
    }
}
コード例 #10
0
ファイル: avlBKP.c プロジェクト: ruimiguelsantos/cstructspoc
Tree insertTree(Tree t, TreeEntry e, int *cresceu) {

  if(!t) {
    t = (Tree) malloc(sizeof(struct treenode));
    t -> entry = e;
    t -> left = NULL;
    t -> right = NULL;
    t -> bf = EH;
    *cresceu = 1;
  }
  else if(e == t->entry)
    printf("\n[error] %d already in tree.\n",e);
  else if(e > t->entry)
    t = insertRight(t, e, cresceu);
  else
    t = insertLeft(t, e, cresceu);

  return(t);
}
コード例 #11
0
ファイル: DQStrings.c プロジェクト: Anam9/CSE-Labs
int main(int argc, const char * argv[]) {
	
	DQUEUE_p_t queue = (DQUEUE_p_t)calloc(SIZE, sizeof(DQUEUE_t));
	initQueue (queue);
	
	char choice;
	
	do {
		printf("\n------------------------------------------------------------\n | 1. Insert Left\n | 2. Insert Right\n | 3. Delete Left\n | 4. Delete Right\n | 5. Display Queue.\n | Q. Quit\n | Enter choice : ");
		choice = getchar();
		getchar();
		
		char * item = (char *)malloc(SIZE * sizeof(char));
		
		if (choice == '1') {
			printf("\n | Enter item to be inserted: ");
			fgets(item, SIZE, stdin);
			insertLeft(queue, item);
		}
		else if (choice == '2') {
			printf("\n | Enter item to be inserted: ");
			fgets(item, SIZE, stdin);
			insertRight(queue, item);
		}
		else if (choice == '3') {
			item = deleteLeft(queue);
			if (item != UNDERFLOW_CHAR)
				printf("\n | Deleted item: %s\n", item);
		}
		else if (choice == '4') {
			item = deleteRight(queue);
			if (item != UNDERFLOW_CHAR)
				printf("\n | Deleted item: %s\n", item);
		}
		
		display(*queue);
		
	} while (choice >= '1' && choice <= '5');
	
	return 0;
}
コード例 #12
0
ファイル: BinaryTree.c プロジェクト: Praneethgoli/c-c--
/*
*Create - sub tree of current node:
*Logic: if: there exist left child
*          insertLeft
*       else: 
*           make leftChild as NULL 
*       if : there exist right child
*           insertRight
*       else:
*           make rightChild as NULL
* call recursively for each node
*/
void createSubTree(node *ptr){
  char ch;
  printf("Sub tree of %d\n",ptr->data);  
  fflush(stdin);
  getchar();
  printf("Is left child 'y':");
  scanf("%c",&ch);
  if(ch == 'y' || ch == 'Y')
    insertLeft(ptr);
  printf("Is right child 'y':");
  fflush(stdin);
  getchar();
  scanf("%c",&ch);
  if(ch == 'y' || ch == 'Y')
    insertRight(ptr);
  if(ptr->left != NULL){
    printf("\nCreate sub tree of %d:\n",ptr->left->data);
    createSubTree(ptr->left);
  }
  if(ptr->right != NULL){
    printf("\nCreate sub tree of %d:\n",ptr->right->data);
    createSubTree(ptr->right);
  }
}