Beispiel #1
0
static void
grow_fields_arr(long num)
{
	int t;
	NODE *n;

	erealloc(fields_arr, NODE **, (num + 1) * sizeof(NODE *), "grow_fields_arr");
	for (t = nf_high_water + 1; t <= num; t++) {
		getnode(n);
		*n = *Null_field;
		fields_arr[t] = n;
	}
	nf_high_water = num;
}
Beispiel #2
0
static struct argnod *r_arg(Shell_t *shp)
{
	register struct argnod *ap=0, *apold, *aptop=0;
	register long l;
	Stk_t		*stkp=shp->stk;
	while((l=sfgetu(infile))>0)
	{
		ap = (struct argnod*)stkseek(stkp,(unsigned)l+ARGVAL);
		if(!aptop)
			aptop = ap;
		else
			apold->argnxt.ap = ap;
		if(--l > 0)
		{
			sfread(infile,ap->argval,(size_t)l);
			ccmaps(ap->argval, l, CC_ASCII, CC_NATIVE);
		}
		ap->argval[l] = 0;
		ap->argchn.cp = 0;
		ap->argflag = sfgetc(infile);
		if((ap->argflag&ARG_MESSAGE) && *ap->argval)
		{
			/* replace international messages */
			ap = sh_endword(shp,1);
			ap->argflag &= ~ARG_MESSAGE;
			if(!(ap->argflag&(ARG_MAC|ARG_EXP)))
				ap = sh_endword(shp,0);
			else
			{
				ap = (struct argnod*)stkfreeze(stkp,0);
				if(ap->argflag==0)
					ap->argflag = ARG_RAW;
			}
		}
		else
			ap = (struct argnod*)stkfreeze(stkp,0);
		if(*ap->argval==0 && (ap->argflag&~(ARG_APPEND|ARG_MESSAGE|ARG_QUOTED))==0)
		{
			struct fornod *fp = (struct fornod*)getnode(shp->stk,fornod);
			fp->fortyp = sfgetu(infile);
			fp->fortre = r_tree(shp);
			fp->fornam = ap->argval+1;
			ap->argchn.ap = (struct argnod*)fp;
		}
		apold = ap;
	}
	if(ap)
		ap->argnxt.ap = 0;
	return(aptop);
}
void inserts(struct pqueue *q,int e)                            
{
          int p,y=NUL,x;
          p=getnode();
          if(p!=NUL)
          {
           x = q->front;
           while(x!=NUL)
           {
                        if(e<l[x].info) 
                        {
                            break;
                        }                                                   
                        y=x;                 
                        x=l[x].next;             
           }          
           if(q->front==NUL)                     //first element
           {
                       l[p].info=e;
                       l[p].next=NUL;
                       q->front=p;
                       q->rear=p;
           }
           else
           {
               if(x==NUL)                        //last entry
               {
                       l[p].info=e;
                       l[p].next=NUL;
                       q->rear=p;      
                       l[y].next=p;
               }
               else                             //between
               {
                       if(y!=NUL)
                       {
                                  l[p].info=e;
                                  l[p].next=l[y].next;
                                  l[y].next =p;
                       }
                       else                           //Insert at beginning
                       {
                                  l[p].info=e;
                                  l[p].next=q->front;
                                  q->front=p;
                       }
               }          
           }
          }     
}
Beispiel #4
0
/*
 * Finds all the ,v files in the argument directory, and adds them to the
 * files list.  Returns 0 for success and non-zero if the argument directory
 * cannot be opened, in which case errno is set to indicate the error.
 * In the error case LIST is left in some reasonable state (unchanged, or
 * containing the files which were found before the error occurred).
 */
static int find_rcs (const char *dir, List *list, const char *regex)
{
    Node *p;
    struct dirent *dp;
    DIR *dirp;

	/* set up to read the dir */
    if ((dirp = opendir (dir)) == NULL)
	return (1);

	/* read the dir, grabbing the ,v files */
    errno = 0;
    while ((dp = readdir (dirp)) != NULL)
    {
		if (CVS_FNMATCH (RCSPAT, dp->d_name, CVS_CASEFOLD) == 0) 
		{
			char *comma, *q;

			comma = strrchr (dp->d_name, ',');	/* strip the ,v */
			*comma = '\0';

			if(!fncmp(dp->d_name,RCSREPOVERSION))
				continue;

			q = map_fixed_rename(dir,dp->d_name);

			if(q && *q && (!regex || regex_filename_match(regex, q)))
			{
				p = getnode ();
				p->type = FILES;
				p->key = xstrdup (q);
				if(!findnode_fn(list,p->key))
				{
					if(addnode (list, p) != 0)
						freenode (p);
				}
			}
		}
		errno = 0;
    }
    if (errno != 0)
    {
	int save_errno = errno;
	(void) closedir (dirp);
	errno = save_errno;
	return 1;
    }
    (void) closedir (dirp);
    return (0);
}
void
init_fields()
{
	NODE *n;

	emalloc(fields_arr, NODE **, sizeof(NODE *), "init_fields");
	getnode(n);
	*n = *Nnull_string;
	n->flags |= (SCALAR|PERM);
	fields_arr[0] = n;
	parse_extent = fields_arr[0]->stptr;
	save_FS = dupnode(FS_node->var_value);
	field0_valid = TRUE;
}
Beispiel #6
0
void insert(NT*plist,int x)
{
NT p,q;
p=getnode();
p->info=x;
p->next=NULL;
if(*plist==NULL)
*plist=p;
else
{
for(q=*plist;q->next!=NULL;q=q->next);
q->next=p;
}
}
genpt copytree(genpt a){
	genpt temp=a;
	genpt ret,front=NULL;
	genpt final;
	int flag=0;

	while(temp!=NULL){
		if(temp->tag==data){
			ret=getnode(temp->u.c,NULL);
		}
		else
			ret=getnode(NULL,copytree(temp->u.list));
		if(flag==0){
			final=ret;
			flag=1;
		}
		if(front!=NULL)
			front->link=ret;
		ret->tag=temp->tag;
		ret->link=temp->link;
		front=ret;
		temp=temp->link;
	}
Beispiel #8
0
int main(){

	int data = -1;
	int label = 0;
	printf("Provide data for the root node\n");
	scanf("%d",&data);
	nodeptr root = getnode(label,data);
	
	createTree(root);
	
	printf("\n=====================Preorder Traversal====================\n");
	pretrav(root);
return 0;
}
void main() {

	struct treenode *root = getnode(10);
	root->left = getnode(5);
	root->right = getnode(15);
	root->left->left = getnode(3);
	root->left->right = getnode(7);
	root->right->left = getnode(13);
	root->right->right = getnode(17);
	//inorder(root);
	inorder_iterative(root);

}
Beispiel #10
0
void main() {
	struct treenode *root = getnode(5);
	root->left = getnode(4);
	root->left->left = getnode(3);
	root->left->right= getnode(8);
	root->right= getnode(7);
	root->right->left = getnode(6);
	root->right->right= getnode(9);

	struct listnode *node = getlistnode();
	get_vertical_sum(root, node);
	printsum(node);
}
Beispiel #11
0
struct node *insert(struct node *rear)
{
    int item;
    struct node *temp;
    printf("\nEnter item to be inserted ");
    scanf("%d",&item);
    temp=getnode();
    rear->link=temp;
    rear=temp;
    temp->link=NULL;
    temp->node=item;
    printf("\nItem successfully inserted...");

    return rear;
};
nodeptr create_poly(float c,int x,nodeptr head)
{
    nodeptr temp,cur;
    temp=getnode();
    temp->cf=c;
    temp->px=x;
    cur=head->link;
    while(cur->link!=head)
    {
        cur=cur->link;
    }
    cur->link=temp;
    temp->link=head;
    return head;
}
node knn(node root)
{
node temp;
for(i=0;i<943;i++)//for user
{
	temp=getnode(i);
	for(j=0;j<943;j++)//with other users
	{
		if(i==j)
		continue;
		eq1=eq2=sum=0;
		for(k=0;k<1682;k++)//for movies
		{
			if(r[i][k]!=0)//if user rated
				eq1+=pow(r[i][k],2);
			if(r[j][k]!=0)//if compared user rated
				eq2+=pow(r[j][k],2);
			if((r[i][k]!=0)&&(r[j][k]!=0))//intersection(both rated)
				sum+=r[i][k]*r[j][k];
		}
	d1=(sqrt(eq1)*sqrt(eq2));
	cosfu=sum/d1;
	if(temp->count<10)
	{
		temp->array[temp->count]=j;
		cosine[temp->count]=cosfu;
		temp->count++;
		continue;					
	}
	min=1;
	for(p=0;p<10;p++)//to get least value in the array
	{
		if(cosine[p]<min)
		{
			min=cosine[p];
			v=p;
		}
	}
	if(cosine[v]<cosfu)
	{
		temp->array[v]=j;
		cosine[v]=cosfu;
	}
	}
	root=insert(temp,root);
	}
	return root;
}
int main()
{
    np p=NULL,list=NULL;
    list=getnode();
    list->info=0;
    list->next=NULL;
    int c=0,x;
    while(c!=6)
    {
        printf("\n1.insert f\t2.delf\t3.ins after\t4.del after\t5.display\t6.exit\n");
        scanf("%d",&c);
        switch(c)
        {
            case 1:printf("enter ele to insert\n");
                   scanf("%d",&x);
                   ins(list,x);
                   break;
            case 2:del(list);
                   break;
            case 3:printf("enter ele to ins after\n");
                   scanf("%d",&x);
                   p=fin(x,list);
                   if(p==NULL)
                   printf("No node found\n");
                   else
                   {
                       printf("enter data of new node\n");
                       scanf("%d",&x);
                       ins(p,x);
                   }
                   break;
           case 4:printf("enter ele to ins after\n");
                   scanf("%d",&x);
                   p=fin(x,list);
                   if(p==NULL)
                   printf("No node found\n");
                   else
                       del(p);
                   break;
          case 5:dis(list);
                 break;
          case 6:printf("Tired huh.....???\n");
                 break;
          default:printf("Wrong input\n");
        }
    }
    return 0;
}
Beispiel #15
0
//function to add new nodes to the tree
void addnew( struct node **q,int data )
{
	if( *q == NULL )
	{
	   *q = getnode( );
	   (*q)->left = NULL;
	   (*q)->right =NULL;
	   (*q)->data = data;
	   return;
	}

	if( (*q)->data > data )
	 addnew( &(*q)->left , data );
	else
	 addnew( &(*q)->right , data );
}
int input(char *filename,LIST l)
{
	FILE *fp=fopen(filename,"rb");
	if (!fp)
		return 0;
	DAILY x;
	NODE *p;
	while (fread(&x,sizeof(DAILY),1,fp))
	{
		DAILY x;
		p=getnode(x);
		addtail(l,p);
	}
	fclose(fp);
	return 1;
}
Beispiel #17
0
void printnodes(BTREE *tree, bnode *node)
{
	int x,y=0;

	printf("(%ld):", node->start );
	for (x = 0; x< node->n; x++)
		printf("%ld ", node->key[x]);

	if (node->isleaf)
		return;

	for (y=0;y < node->n+1; y++){
		printf("\n");
		printnodes(tree, getnode(tree, node->children[y]));
	}
}
Beispiel #18
0
void insafter(nodeptr q, char x)
{
  nodeptr r;
  if(q==NULL)
  {
    printf("Void insertion\n");
    exit(1);
  }
  else
  {
    r=getnode();
    r->info=x;
    r->next=q->next;

  }
}
int input(char *filename,LIST &l)
{
	FILE *fp=fopen(filename,"rb");
	if (!fp)
		return 0;
	HOPSUA x;
	init(l);
	NODE *p;
	while (fread(&x,sizeof(HOPSUA),1,fp))
	{
		p=getnode(x);
		addtail(l,p);
	}
	fclose(fp);
	return 1;
}
Beispiel #20
0
void setleft(NODEPTR p,int x)
{
	NODEPTR q;
	if(p==NULL)
		error("void insertion");
	else if(p->left!=NULL)
		error("invalid insertion");
	else{
		q=getnode();
	q->info=x;
	p->left=q;
	q->left=NULL;
	q->right=p;
	q->rthread=TRUE;
}
}
Beispiel #21
0
TreeNode*  sortedListToBST(ListNode  * &head, int n)
{
if(n <= 0 )
return NULL;
if(head  == NULL)
return NULL;
   
    
TreeNode  *leftNode  =   sortedListToBST(head,  n / 2);
TreeNode *root  =    getnode(head->val);
head  = head->next;
TreeNode  *rightNode  =   sortedListToBST(head, n  - n / 2 - 1);
root->left  = leftNode;
root->right  = rightNode;
return root;
}
Beispiel #22
0
/*
 * add the key from entry on entries list to the files list
 */
static int add_entries_proc(Node *node, void *callerdat)
{
    Entnode *entnode;
    Node *fnode;

    entnode = (Entnode *) node->data;
    if (entnode->type != ENT_FILE)
		return (0);

    fnode = getnode ();
    fnode->type = FILES;
    fnode->key = xstrdup (node->key);

	if (addnode (filelist, fnode) != 0)
		freenode (fnode);
    return (0);
}
Beispiel #23
0
/*FUNCTION*/
LVAL c_cons(tpLspObject pLSP
  ){
/*noverbatim
CUT*/
/*
TO_HEADER:
#define cons() c_cons(pLSP)
*/
   LVAL p;

   if( null((p = getnode())) )
      return NIL;
   settype(p,NTYPE_CON);
   setcar(p,NIL);
   setcdr(p,NIL);
   return p;
}
Beispiel #24
0
void
Insert (trienode *root, char *key) 
{
	trienode *walk = root;

	int len = strlen (key);
	int level = 0;

	for (level=0; level < len; level++) {
		index = key[level] - 'a';
		if (!walk->children[index])
			walk->children[index] = getnode(key[level]);
		walk = walk->children[index];
	}

	walk->isLeaf = 1;
}
Beispiel #25
0
int main()
{
int n;
node *root=0,*newnode;
printf("enter info and enter -999 for end\n");
scanf("%d",&n);
while(n!=-999)
{
if(n==-999)
break;
newnode=getnode(n);
root=insert(root,newnode);
scanf("%d",&n);
}
preorder(root);
getch(); 
}
void _input(char *filename,LIST &l)
{
	FILE *fp=fopen(filename,"wt");
	int n;
	fscanf(fp,"%d" ,n);	
	for (int i=0;i<n;i++)
		DAILY x;		
		fgets(x.madaily,6,fp);
		fgets(x.tendaily,31,fp);
		fscanf(fp,"%d" ,&x.dienthoai);
		fprintf(fp,"%d %d %d" ,&x.ngaytiepnhan.ng,
			&x.ngaytiepnhan.th,x.ngaytiepnhan.nm);
		fgets(x.diachi,51,fp);
		fgets(x.email,51,fp);		
		NODE *p=getnode(x);
		addtail(l,p);
	}
Beispiel #27
0
void
deletebtree(
	BTREE* btree
)
{
	struct bt_node *node = getnode(btree->root);

	if (node->addr0 != ADDR_NULL) {
		int i;
		for (i = 0; i < node->size; i++) {
			free((void *) node->entries[i].addr);
		}
	}

	free(node);
	free(btree);
}
Beispiel #28
0
static int add_subdir_proc (Node *p, void *closure)
{
    List *dirlist = (List *) closure;
    Entnode *entnode;
    Node *dnode;

    entnode = (Entnode *) p->data;
    if (entnode->type != ENT_SUBDIR)
	return 0;

    dnode = getnode ();
    dnode->type = DIRS;
    dnode->key = xstrdup (entnode->user);
    if (addnode (dirlist, dnode) != 0)
	freenode (dnode);
    return 0;
}
struct node *addatbeg(struct node *q,int ele)
{
struct node *temp,*r;
temp=getnode();
temp->item=ele;
temp->l=NULL;
temp->r=NULL;
if(q==NULL)
{
q=temp;
return q;
}
temp->r=q;
q->l=temp;
q=temp;
return q;
}
Beispiel #30
0
void setright(NODEPTR p,int x)
{
	NODEPTR q,r;
	if(p==NULL)
		error("void insertion");
	else if(!p->rthread)
		error("invalid insertion");
	else{
		q=getnode();
	q->info=x;
	r=p->right;
	p->right=q;
	p->rthread=FALSE;
	q->left=NULL;
	q->right=r;
	q->rthread=TRUE;
	}
}