예제 #1
0
void asm_repnode(ENODE **node)
{
    if ((*node)->nodetype == en_add || (*node)->nodetype == en_addstruc)
    {
        asm_repnode(&(*node)->v.p[0]);
        asm_repnode(&(*node)->v.p[1]);
    }
    else
    if ((*node)->nodetype == en_autocon || (*node)->nodetype == en_autoreg)
    {
        *node = makeintnode(en_icon, (*node)->v.sp->value.i);
    }
    else if ((*node)->nodetype == en_nacon || (*node)->nodetype == en_napccon)
    {
        *node = makenode((*node)->nodetype, (*node)->v.sp, 0);
    }
    else if ((*node)->nodetype == en_nalabcon)
    {
        *node = makenode((*node)->nodetype, (*node)->v.sp, 0);
    }
    else if ((*node)->nodetype == en_labcon)
    {
        *node = makeintnode((*node)->nodetype, (*node)->v.i);
    }
    else if ((*node)->nodetype == en_absacon)
    {
        *node = makeintnode(en_absacon, ((SYM*)(*node)->v.p[0])->value.i);

    }
}
예제 #2
0
void insert(nsp *btp,int x)
{
  nsp tmp = *btp;
  if (*btp == 0) {
    *btp = makenode(x);
    return;
  }

  while (1) 
  {
    if (x < tmp->val) {
      if (tmp->left != 0) {
        tmp = tmp->left;
      }
      else {
        tmp->left = makenode(x);
        break;
      }
      }else {
        if (tmp->right != 0) {
          tmp = tmp->right;
        }
        else {
          tmp->right = makenode(x);
          break;
        }
      }
  }

}
예제 #3
0
int main(){
  treeinitialize();

  /* テスト用の木を作成 */
  head->right=makenode('+');
  head->right->left=makenode('1');
  head->right->right=makenode('*');
  head->right->right->left=makenode('2');
  head->right->right->right=makenode('3');


  /* トラバース */
  printf("preorder:  ");
  preorder(head->right);
  printf("\n");

  printf("inorder:   ");
  inorder(head->right);
  printf("\n");

  printf("postorder: ");
  postorder(head->right);
  printf("\n");

  return 0;
}
NODE* breaknode(NODE *p, int j, int i, int s)
{

	//printf("break node\n");
	int id = findid(p->start);
			
	NODE * q= makenode(p->start,j-1, internalID,p->depth- (p->end-j+1) );
	internalID++;
	//printf("make internal %d, %d, %d, %d\n",  q->id,q->start, q->end, q->depth);

	

	q->parent= p->parent;
	p->parent->children[id] = q;
						
				
	// update p
	p->start= j;
	p->parent=q;
				
	id= findid(j);					
	q->children[id]=p;							
			
	NODE * leaf=makenode( i, seqlength-1, s, seqlength-i+q->depth);
	//printf("makeleaf %d, %d, %d, %d\n",  leaf->id,leaf->start, leaf->end, leaf->depth);						
	leaf->parent= q;					
	id= findid(i);
	q->children[id]=leaf;
					
	return leaf;

				
}
예제 #5
0
파일: blockgen.c 프로젝트: 00001/plan9port
obj*
rightthing(obj *p, int c)	/* called for ... ] or ... } */
{
	obj *q;

	if (c == '}') {
		nbstack--;
		curx = bracestack[nbstack].p_x;
		cury = bracestack[nbstack].p_y;
		hvmode = bracestack[nbstack].p_hvmode;
		q = makenode(MOVE, 0);
		dprintf("M %g %g\n", curx, cury);
	} else {
		nstack--;
		curx = stack[nstack].p_x;
		cury = stack[nstack].p_y;
		hvmode = stack[nstack].p_hvmode;
		q = makenode(BLOCKEND, 7);
		q->o_val[4] = p->o_nobj + 1;	/* back pointer */
		p->o_val[5] = q->o_nobj - 1;	/* forward pointer */
		p->o_val[0] = xmin; p->o_val[1] = ymin;
		p->o_val[2] = xmax; p->o_val[3] = ymax;
		p->o_symtab = q->o_symtab = stack[nstack+1].p_symtab;
		xmin = stack[nstack].p_xmin;
		ymin = stack[nstack].p_ymin;
		xmax = stack[nstack].p_xmax;
		ymax = stack[nstack].p_ymax;
	}
	return(q);
}
예제 #6
0
void InsertNth(struct node** headRef, int index, int data) {
	struct node* current = *headRef;
	int i;
	if (index == 0)
		makenode(headRef, data);
	else{
		for (i=0; i<index-1; i++) {
			current = current->next;
		}
		makenode(&(current->next), data);
	}
}
예제 #7
0
파일: blockgen.c 프로젝트: 00001/plan9port
obj*
leftthing(int c)	/* called for {... or [... */
			/* really ought to be separate functions */
{
	obj *p;

	if (c == '[') {
		if (nstack >= NBRACK)
			ERROR "[...] nested too deep" FATAL;
		stack[nstack].p_x = curx;
		stack[nstack].p_y = cury;
		stack[nstack].p_hvmode = hvmode;
		curx = cury = 0;
		stack[nstack].p_xmin = xmin;
		stack[nstack].p_xmax = xmax;
		stack[nstack].p_ymin = ymin;
		stack[nstack].p_ymax = ymax;
		nstack++;
		xmin = ymin = 30000;
		xmax = ymax = -30000;
		p = makenode(BLOCK, 7);
		p->o_val[4] = nobj;	/* 1st item within [...] */
		if (p->o_nobj != nobj-1)
			fprintf(stderr, "nobjs wrong%d %d\n", p->o_nobj, nobj);
	} else {
		if (nbstack >= NBRACK)
			ERROR "{...} nested too deep" FATAL;
		bracestack[nbstack].p_x = curx;
		bracestack[nbstack].p_y = cury;
		bracestack[nbstack].p_hvmode = hvmode;
		nbstack++;
		p = NULL;
	}
	return(p);
}
예제 #8
0
파일: null.c 프로젝트: glk/puffs
/*ARGSUSED*/
int
puffs_null_node_mknod(struct puffs_usermount *pu, puffs_cookie_t opc,
	struct puffs_newinfo *pni, const struct puffs_cn *pcn,
	const struct vattr *va)
{
	mode_t mode;
	int rv;

	mode = puffs_addvtype2mode(va->va_mode, va->va_type);
	switch (va->va_type) {
	case VFIFO:
		if (mkfifo(PCNPATH(pcn), mode) == -1)
			return errno;
		break;
	case VCHR:
	case VBLK:
		if (mknod(PCNPATH(pcn), mode, va->va_rdev) == -1)
			return errno;
		break;
	default:
		return EINVAL;
	}

	rv = makenode(pu, pni, pcn, va, 0);
	if (rv)
		unlink(PCNPATH(pcn));
	return rv;
}
예제 #9
0
//Insert a new leaf in the tree. Each time a new leaf is inserted, the balance of the tree is checked
//There are 4 different cases in which a tree is unbalanced
//Because the function is recursive, each function call returns the (modified) root to the previous function call. The result is that we have pointers to all ancestor nodes of the inserted node.
//Tree is balanced while climbing up the tree.
TREE* insert(TREE *root, char *name,char *phone){
    if(root==NULL){
        root = makenode(name,phone,NULL,NULL);
    }else if(strcmp(name,root->name)==0){
        free(name);
        insertPhone(&(root->phones),phone);
    }else if(strcmp(name,root->name)<0){
        root->left = insert(root->left,name,phone);
        #if BALANCE == 1
        (Height(root->left)>Height(root->right)) ? (root->height=Height(root->left)+1) : (root->height=Height(root->right)+1) ; //Choose the maximum height of the two subtrees and add one to get the height of current tree.
        //****Balancing****
        if( (Height(root->left)-Height(root->right)) >1){ //If there's a difference in heights, greater than 1 => left subtree is bigger than right one.
            if(strcmp(name,root->left->name)>0) {        //Choose between case (a) or case (b). Case (b) requires an additional left rotation of the left child node
                root->left=rotateLeft(root->left);
            }
            return rotateRight(root);
        }
        //*****************
        #endif
    }else{
        root->right = insert(root->right,name,phone);
        #if BALANCE == 1
        (Height(root->left)>Height(root->right)) ? (root->height=Height(root->left)+1) : (root->height=Height(root->right)+1) ; //Choose the maximum height of the two subtrees and add one to get the height of current tree.
        //****Balancing****
        if( (Height(root->right)-Height(root->left)) >1){ //If there's a difference in heights, greater than 1 => right subtree is bigger than left one.
            if(strcmp(name,root->right->name)<0) {       //Choose between case (c) or case (d). Case (d) requires an additional right rotation of the right child node
                root->right=rotateRight(root->right);
            }
            return rotateLeft(root);
        }
        //*****************
        #endif
    }
    return root;
}
예제 #10
0
struct puffs_node *
allocnode(struct puffs_usermount *pu, struct puffs_node *parent,
	const char *entryname, const struct vattr *vap)
{
	struct psshfs_ctx *pctx = puffs_getspecific(pu);
	struct psshfs_dir *pd;
	struct puffs_node *pn;

	pd = direnter(parent, entryname);

	pd->va.va_fileid = pctx->nextino++;
	if (vap->va_type == VDIR) {
		pd->va.va_nlink = 2;
		parent->pn_va.va_nlink++;
	} else {
		pd->va.va_nlink = 1;
	}

	pn = makenode(pu, parent, pd, vap);
	if (pn) {
		pd->va.va_fileid = pn->pn_va.va_fileid;
		pd->entry = pn;
	}

	return pn;
}
예제 #11
0
파일: misc.c 프로젝트: 99years/plan9
obj *makepos(double x, double y)	/* make a position cell */
{
	obj *p;

	p = makenode(PLACE, 0);
	p->o_x = x;
	p->o_y = y;
	return(p);
}
예제 #12
0
void makelist(struct node** head)
{
        int i = 0;
        *head = 0;
        for(;i<10; i++)
                makenode(head,i);
        print_list(*head);

}
예제 #13
0
AMODE    *make_strlab(char *s)
/*
 *      generate a direct reference to a string label.
 */
{       AMODE    *ap;
        ap = xalloc(sizeof(AMODE));
        ap->mode = am_direct;
        ap->offset = makenode(en_nacon,s,0);
        return ap;
}
예제 #14
0
파일: misc.c 프로젝트: 99years/plan9
obj *makebetween(double f, obj *p1, obj *p2)	/* make position between p1 and p2 */
{
	obj *p;

	dprintf("fraction = %.2f\n", f);
	p = makenode(PLACE, 0);
	p->o_x = p1->o_x + f * (p2->o_x - p1->o_x);
	p->o_y = p1->o_y + f * (p2->o_y - p1->o_y);
	return(p);
}
예제 #15
0
void gencompactswitch(SNODE *stmt, int deflab)
{       int             tablab,curlab,i, size = natural_size(stmt->exp);
        AMODE    *ap,*ap2;
  long switchbottom=gswitchbottom, switchcount=gswitchcount;
  long switchtop=gswitchtop;
  int *switchlabels=0;
				tablab = nextlabel++;
        curlab = nextlabel++;
        initstack();
        ap = gen_expr(stmt->exp,F_DREG | F_VOL,4);
				initstack();
				if (switchbottom)
					gen_code(op_sub,4,ap,make_immed(switchbottom));
				if (size < 0)
					gen_code(op_jl,0,make_label(deflab),0);
				else
					gen_code(op_jb,0,make_label(deflab),0);
				gen_code(op_cmp,4,ap,make_immed(switchtop-switchbottom));
				if (size < 0)
					gen_code(op_jge,0,make_label(deflab),0);
				else
					gen_code(op_jnc,0,make_label(deflab),0);
				gen_code(op_shl,4,ap,make_immed(2));
				ap2 = xalloc(sizeof(AMODE));
				ap->mode = am_indisp;
				ap2->preg = ap->preg;
				ap->offset = makenode(en_labcon,(char *)tablab,0);
				gen_code(op_jmp,4,ap,0);

				initstack();
				align(4);
				gen_label(tablab);
		switchlabels = xalloc((switchtop-switchbottom) * sizeof(int));
	for (i=switchbottom; i < switchtop; i++) {
		switchlabels[i-switchbottom] = deflab;
	}
	stmt = stmt->s1;
	while (stmt) {
                if( stmt->s2 )          /* default case ? */
                        {
                        stmt->label = (SNODE *)deflab;
												diddef = TRUE;
                        }
                else
                        {
												switchlabels[(int)stmt->label-switchbottom] = curlab;
												stmt->label = (SNODE *)curlab;
                        }
                if(stmt->next != 0 )
                        curlab = nextlabel++;
                stmt = stmt->next;
                }
	for (i=0; i < switchtop-switchbottom; i++)
		gen_code(op_dd,4,make_label(switchlabels[i]),0);
}
예제 #16
0
Statement *ParseCatchStatement()
{
	Statement *snp;
	SYM *sp;
	TYP *tp,*tp1,*tp2;
    ENODE *node;
    static char buf[200];
    
	snp = NewStatement(st_catch, TRUE);
	currentStmt = snp;
	if (lastst != openpa) {
		snp->label = (int64_t *)NULL;
		snp->s2 = (Statement *)99999;
		snp->s1 = ParseStatement();
		// Empty statements return NULL
		if (snp->s1)
			snp->s1->outer = snp;
		return snp;
	}
    needpunc(openpa,33);
	tp = head;
	tp1 = tail;
	catchdecl = TRUE;
	AutoDeclaration::Parse(NULL,&snp->ssyms);
	cseg();
	catchdecl = FALSE;
	tp2 = head;
	head = tp;
	tail = tp1;
    needpunc(closepa,34);
    
	if( (sp = snp->ssyms.Find(*declid,false)) == NULL)
        sp = makeint((char *)declid->c_str());
    node = makenode(sp->storage_class==sc_static ? en_labcon : en_autocon,NULL,NULL);
    // nameref looks up the symbol using lastid, so we need to back it up and
    // restore it.
    strncpy(buf,lastid,199);
    strncpy(lastid, declid->c_str(),sizeof(lastid)-1);
    nameref(&node,FALSE);
    strcpy(lastid,buf);
	snp->s1 = ParseStatement();
	// Empty statements return NULL
	if (snp->s1)
		snp->s1->outer = snp;
	snp->label = (int64_t *)node;	// save name reference
	if (sp->tp->typeno >= bt_last)
		error(ERR_CATCHSTRUCT);
	snp->s2 = (Statement *)GetTypeHash(sp->tp);
	// Empty statements return NULL
//	if (snp->s2)
//		snp->s2->outer = snp;
	return snp;
}
예제 #17
0
graf_init()
	{
	int arctype[3];  long arclab[3];
	nodenum = 0;
	doptr = UNDEFINED;
	retvert = stopvert = UNDEFINED;
	ENTLST = FMTLST = 0;

	
	arctype[0] = -2;  arclab[0] = implicit;
	START = makenode(DUMVX,FALSE,FALSE,implicit,1,arctype,arclab);
	}
예제 #18
0
void put( int key, int value)
{
    node *ptr, *save, *n;

    if(root == NULL)
    {
       root = makenode();
       root -> key = key;
       root -> value = value;
       return;
    }
    else
    {
       ptr = root;

       while(ptr != NULL)
       {
           if(ptr -> key > key)
           {
                save = ptr;
                save -> count += 1;
                ptr = (node*)ptr -> left;
           }
           else{
               save = ptr;
               save -> count += 1;
               ptr = (node*)ptr -> right;
           }
       }
       
       n = makenode();
       n -> key = key;
       n -> value = value;
      
       if(save -> key < key)
            save -> right = (struct node*)n;
       else
            save -> left = (struct node*)n;
    }        
}    
bool maketree(int* a,int n){
	if(!a || n<=0){
		printf("Please enter valid inputs array of intgers and its size to make tree\n");
		return false;
	}
	root=(node*)malloc(sizeof(node));
	makenode(root,a[0]);
	node_count++;
	int i;
	for(i=1;i<n;i++){
		node* tmp=root;
		while(tmp){
			if(a[i]<=tmp->data){
				if(tmp->l){
					tmp=tmp->l;
					continue;
				}
				else{
					tmp->l=(node*)malloc(sizeof(node));
					makenode(tmp->l,a[i]);
					node_count++;
					break;
				}
			}		
			if(a[i]>tmp->data){
				if(tmp->r){
					tmp=tmp->r;
					continue;
				}
				else{
					tmp->r=(node*)malloc(sizeof(node));
					makenode(tmp->r,a[i]);
					node_count++;
					break;
				}		
			}
		}
	}
	return true;
}
예제 #20
0
/*
name: li_insert_after
description: add new node after the node referenced by index
*/
node *li_insert_after(node *head, int index, int data) {
  int i = 0;
  node *ptr = head;
  
  while (i < index) {
    ptr = ptr->next;
    i++;
  }

  node *prevnext = ptr->next;
  ptr->next = makenode(data);
  ptr->next->next = prevnext;
}
예제 #21
0
파일: misc.c 프로젝트: n-t-roff/DWB3.3
obj *
makepos(double x, double y, int corner, obj *q)	/* make a position cell */
{
	obj *p;

	p = makenode(PLACE, 1, 0);
	if (q)
		p->o_parent = q;
	p->o_x = x;
	p->o_y = y;
	p->o_val[0].f = corner;
	return(p);
}
예제 #22
0
파일: null.c 프로젝트: glk/puffs
/*ARGSUSED*/
int
puffs_null_node_mkdir(struct puffs_usermount *pu, puffs_cookie_t opc,
	struct puffs_newinfo *pni, const struct puffs_cn *pcn,
	const struct vattr *va)
{
	int rv;

	if (mkdir(PCNPATH(pcn), va->va_mode) == -1)
		return errno;

	rv = makenode(pu, pni, pcn, va, 0);
	if (rv)
		rmdir(PCNPATH(pcn));
	return rv;
}
예제 #23
0
파일: null.c 프로젝트: glk/puffs
/*ARGSUSED*/
int
puffs_null_node_symlink(struct puffs_usermount *pu, puffs_cookie_t opc,
	struct puffs_newinfo *pni, const struct puffs_cn *pcn,
	const struct vattr *va, const char *linkname)
{
	int rv;

	if (symlink(linkname, PCNPATH(pcn)) == -1)
		return errno;

	rv = makenode(pu, pni, pcn, va, 0);
	if (rv)
		unlink(PCNPATH(pcn));
	return rv;
}
예제 #24
0
파일: Optimize.cpp 프로젝트: robfinch/Cores
/*
 *      reorganize an expression for optimal constant grouping.
 */
static void fold_const(ENODE **node)
{       
	ENODE *ep;
    int64_t i;

        ep = *node;
        if( ep == 0 )
                return;
        if( ep->nodetype == en_add )
                {
                if( ep->p[0]->nodetype == en_icon )
                        {
                        ep->p[0]->i += xfold(ep->p[1]);
                        return;
                        }
                else if( ep->p[1]->nodetype == en_icon )
                        {
                        ep->p[1]->i += xfold(ep->p[0]);
                        return;
                        }
                }
        else if( ep->nodetype == en_sub )
                {
                if( ep->p[0]->nodetype == en_icon )
                        {
                        ep->p[0]->i -= xfold(ep->p[1]);
                        return;
                        }
                else if( ep->p[1]->nodetype == en_icon )
                        {
                        ep->p[1]->i -= xfold(ep->p[0]);	// ??? other order ??? xfold - p[1]
                        return;
                        }
                }
        i = xfold(ep);
        if( i != 0 )
                {
                ep = makeinode(en_icon,i);
				ep->etype = (*node)->etype;
				ep->tp = (*node)->tp;
                ep = makenode(en_add,ep,*node);
				ep->etype = (*node)->etype;
				ep->tp = (*node)->tp;
				*node = ep;
                }
}
예제 #25
0
파일: null.c 프로젝트: glk/puffs
/*ARGSUSED*/
int
puffs_null_node_create(struct puffs_usermount *pu, puffs_cookie_t opc,
	struct puffs_newinfo *pni, const struct puffs_cn *pcn,
	const struct vattr *va)
{
	int fd, rv;

	fd = open(PCNPATH(pcn), O_RDWR | O_CREAT | O_TRUNC);
	if (fd == -1)
		return errno;
	close(fd);

	rv = makenode(pu, pni, pcn, va, 1);
	if (rv)
		unlink(PCNPATH(pcn));
	return rv;
}
NODE * findPath(int i, NODE *p, int s)
{

	//printf("findpath \n");
	while(i<seqlength)
	{
		int id =findid(i);
				
		if(p->children[id]==0)
		{
			//printf("IA %d\n", s);
			
			NODE* q= makenode(i,seqlength-1, s, seqlength-i+p->depth); //start end id depht

			//printf("make leaf for %d,%d, %d, %d\n", q->id, q->start,q->end, q->depth);
			p->children[id]=q;
			q->parent=p;
					

			return q;
			
		}	
		else
		{

			//printf("IB %d\n", s);
			p= p->children[id];


			int j=p->start;

			while(j<=p->end && i<seqlength)
			{
				if(sequence[i]!=sequence[j])
					break;
				i++;
				j++;
			}

			if(j<=p->end)		// not match
				return breaknode(p, j, i,s ); // old node, j for update, i for leaf, s for suffix id
			
		}
	}
}
예제 #27
0
파일: misc.c 프로젝트: n-t-roff/DWB3.3
obj *
makebetween(double f, obj *p1, obj *p2)	/* make position between p1 and p2   */
			/* again, transforms must be applied */
{
	obj	*p;
	double	x1, y1, x2, y2;

	p = makenode(PLACE, 3, 0);
	x1 = Xformx(p1, 1, p1->o_x, p1->o_y);
	y1 = Xformy(p1, 0, p1->o_x, p1->o_y);
	x2 = Xformx(p2, 1, p2->o_x, p2->o_y);
	y2 = Xformy(p2, 0, p2->o_x, p2->o_y);
	p->o_x = x1 + f * (x2 - x1);
	p->o_y = y1 + f * (y2 - y1);
	p->o_val[0].f = f;
	p->o_val[1].o = p1;
	p->o_val[2].o = p2;
	return(p);
}
예제 #28
0
파일: 58.c 프로젝트: wj32/Judge
void testcase(void)
{
    int i;
    int min = PEOPLE + 1;
    int max = 0;
    
    scanf("%d %d", &p, &k);
    scanf("%d", &n);
    
    bufferindex = 0;
    count = 1;
    list[0] = makenode();
    list[0]->start = p;
    list[0]->length = k - p + 1;
    list[0]->count = 0;
    
    for (i = 0; i < n; i++)
    {
        int a, b;
        
        scanf("%d %d", &a, &b);
        
        if (a <= k)
        {
            if (a < p)
                a = p;
            if (b > k)
                b = k;
            
            increment(a, b);
        }
    }
    
    for (i = 0; i < count; i++)
    {
        if (min > list[i]->count)
            min = list[i]->count;
        if (max < list[i]->count)
            max = list[i]->count;
    }
    
    printf("%d %d\n", min, max);
}
예제 #29
0
파일: 58.c 프로젝트: wj32/Judge
void split(int x)
{
    int index;
    node *d;
    
    findnode(x, &index);
    d = list[index];
    
    if (d->start < x && x < d->start + d->length)
    {
        node *right;
        
        right = makenode();
        right->start = x;
        right->length = d->length - (x - d->start);
        right->count = d->count;
        insert(index + 1, right);
        
        d->length = x - d->start;
    }
}
예제 #30
0
AMODE *set_symbol(char *name, int flag)
{
    SYM *sp;
    AMODE *ap;
    sp = gsearch(name);
    if (sp == 0)
    {
        ++global_flag;
        sp = makesym(flag ? sc_externalfunc : sc_external);
        sp->tp = &stdfunc;
        sp->name = name;
        sp->extflag = 1;
        insert(sp, gsyms);
        --global_flag;
    }
    ap = xalloc(sizeof(AMODE));
    ap->mode = am_immed;
    ap->length = BESZ_DWORD;
    ap->offset = makenode(en_nacon, sp, 0);
    return ap;
}