예제 #1
0
파일: a14.c 프로젝트: SoftwareHouse/Task3
//h)根据学生学号对链表进行排序(SortId),学号小在前,学号大在后。
struct student *sortid(struct student *head)
{
    struct student *insertnode(struct student *head,struct student *stud);
	struct student *p1,*p2=NULL,*p3,*p4;
	if(head==NULL)
	{
		printf("list null!\n");
		return head;
	}
	p1=head;	
	while(p1!=NULL)
	{
		p4=p2;
	    p2=p1;
	    p1=p1->next;
		if(p1!=NULL)
			if(p2->num>p1->num)
			{
			    p3=p1;
			    p1=p1->next;
			    p2->next=p1;
                p3->next=NULL;
                insertnode(head,p3);
			}
	}
			if(p4->num>p2->num)
			{
			    p3=p2;
                p3->next=NULL;
                insertnode(head,p3);
			}
	return head;
}
예제 #2
0
/* ----------在链表第i个位置插入数据等于x的节点类用例------------- */
void CExampleTest::TestCase02_1()
{
	struct strlnode *p;

	create(&p, 1);
	insertnode(&p, 1, 2);
	insertnode(&p, 2, 3);
	insertnode(&p, 3, 4);

	insertnode(&p, 2, 5);

	CPPUNIT_ASSERT(p->data == 1);
	p = p->pnext;
	CPPUNIT_ASSERT(p->data == 2);
	p = p->pnext;
	CPPUNIT_ASSERT(p->data == 5);
	p = p->pnext;
	CPPUNIT_ASSERT(p->data == 3);
	p = p->pnext;
	CPPUNIT_ASSERT(p->data == 4);
	CPPUNIT_ASSERT(p->pnext == null);

	p = p->plast;
	CPPUNIT_ASSERT(p->data == 3);
	p = p->plast;
	CPPUNIT_ASSERT(p->data == 5);
	p = p->plast;
	CPPUNIT_ASSERT(p->data == 2);
	p = p->plast;
	CPPUNIT_ASSERT(p->data == 1);
	CPPUNIT_ASSERT(p->plast == null);

}
예제 #3
0
struct trie *insertnode(struct trie *root,char *word){
		int i;
		if(!word) return NULL;

	  if(!root){
			struct trie *t=(struct trie*)malloc(sizeof(struct trie));
			 if(!t){
					 printf("memory error");
					 return NULL;
					 }
			 t->data=*word;
			 for(i=0;i<26;i++)
				  t->child[i]=NULL;
			 if(!*(word+1)){
					 t->is_end=1;
					 return t;
							  }
			 else{
					t->is_end=0;
					t->child[index(*word)]=insertnode(t->child[index(*word)],word+1);
					  return t;
				  } }

			  root->child[index(*word)]=insertnode(root->child[index(*word)],word+1);
					 return root;


}
예제 #4
0
파일: bflz.c 프로젝트: aahud/harvey
void
compress(void)
{
	int best, i, j, o, rle, run, maxrun, maxoff;
	uint32_t sum;
	Node *n;

	sum = 0;
	for(i=0; i<win && i<length; i++)
		sum = (sum*256+data[i])%Prime;
	for(i=0; i<length-win; ){
		maxrun = 0;
		maxoff = 0;
		if(verbose)
			fprint(2, "look %.6lux\n", sum);
		n = lookup(sum);
		if(n){
			best = -1;
			for(o=0; o<NOFF; o++){
				if(n->offset[o] == -1)
					break;
				run = cmprun(data+i, data+n->offset[o], length-i);
				if(run > maxrun && n->offset[o]+mindist < i){
					maxrun = run;
					maxoff = n->offset[o];
					best = o;
				}
			}
			if(best > 0){
				o = n->offset[best];
				for(j=best; j>0; j--)
					n->offset[j] = n->offset[j-1];
				n->offset[0] = o;
			}
		}
				
		if(maxrun >= minrun)
			j = i+refblock(i, maxrun, maxoff);
		else
			j = i+rawbyte(i);
		for(; i<j; i++){
			/* avoid huge chains from large runs of same byte */
			rle = countrle(data+i);
			if(rle<4)
				insertnode(sum, i);
			else if(rle>maxrle[data[i]]){
				maxrle[data[i]] = rle;
				insertnode(sum, i);
			}
			sum = (sum*256+data[i+win]) % Prime;
			sum = (sum + data[i]*outn) % Prime;
		}
	}
	/* could do better here */
	for(; i<length; i++)
		rawbyte(i);
	flushraw();
}
예제 #5
0
 void main(){

		char c[]="hot";
	  char d[]="utm";
	  struct trie *curr=insertnode(NULL,c);
	  struct trie *urr=insertnode(curr,d);
	  displaytrie(urr);


}
예제 #6
0
void main(){

 struct cl *c=insertnode(NULL,2);
 insertnode(c,5);
 insertnode(c,8);
 insertnode(c,9);

 displaylist();

}
예제 #7
0
/* ----------获取链表中节点个数类用例------------- */
void CExampleTest::TestCase04_1()
{
	struct strlnode *p;
	int num = 0;

	create(&p, 1);
	insertnode(&p, 1, 2);
	insertnode(&p, 2, 3);
	insertnode(&p, 3, 4);

	num = getnodenum(&p);

	CPPUNIT_ASSERT(num == 4);
}
예제 #8
0
파일: a14.c 프로젝트: SoftwareHouse/Task3
void main()
{
	struct student *creatlink();
	void printlink(struct student *head);
    void searchid(struct student *head,int m);
    struct student *insertnode(struct student *head,struct student *stud);
    struct student *deletenode(struct student *head,int m);
    struct student *sortid(struct student *head);
    void deletelink(struct student *head);
	struct student *head,*stu;
	int m;
    head=creatlink();
	printlink(head);
	printf("input the student id you want\n");
	scanf("%d",&m);
    searchid(head,m);
	printf("\n\nnow it's going to sort it\n\n");
    sortid(head);
	printlink(head);
	printf("then insert a student record\n ");
    stu=(struct student *)malloc(LEN);
    printf("intput the student's id\n");
	scanf("%d",&stu->num);
	printf("input the student's name\n");
	scanf("%s",stu->name);
	printf("input the student's score\n");
	scanf("%f",&stu->score);
    insertnode(head,stu);
    printlink(head);
    printf("now input the student you want to delete\n");
	scanf("%d",&m);
    deletenode(head,m);
    printlink(head);
    deletelink(head);
}
예제 #9
0
int main(void)
{
      int i;
      node **L;

      if (sizeof(int) < 4)
      {
            puts("This code must be compiled with 32-bit ints!");
            return EXIT_FAILURE;
      }

      L=newlist();

      puts(" DOWN");

      for(i = 100; i >= 0; i -=2)
            insertnode(L, i, i);

      puts(" UP");
      for(i = 1; i < 100; i += 2)
            insertnode(L, i, i);

      deletenode(L, 40);

      puts(" FIND");
      for(i = -2; i <= 100; ++i)
            findnode(L, i);

      puts(" FAST");
      findall(L);

      puts("SAMPLES");
      printf(" %d", findnode(L, -10));

      printf(" %d,", findnode(L, 0));
      printf(" %d", findnode(L, 1));
      printf(" %d", findnode(L, 2));
      printf(" %d", findnode(L, 39));
      printf(" %d", findnode(L, 40));
      printf(" %d", findnode(L, 41));
      printf(" %d", findnode(L, 42));

      puts(" DONE");

      return EXIT_SUCCESS;
}
예제 #10
0
void								reverse_rotate(t_env *e, char c)
{
	int								tmp;
	t_lst							*lst;

	lst = (c == 'a') ? e->a : e->b;
	tmp = lst->end->data;
	lst->end = lst->end->prev;
	lst->end->next = NULL;
	lst = insertnode(lst, tmp);
	print(e, (c == 'a') ? "rra" : "rrb");
}
예제 #11
0
NPTR insertnode(NPTR root,NPTR p, NPTR rt)
{
	if(root==NULL)
	{
		root=p;
		if(rt!=NULL)
		{
			root->right=rt;
			root->rthread=1;
		}
	}
	else if(p->info<root->info)
		root->left=insertnode(root->left,p,root);
	     else
		if(root->rthread==1)
		{
			root->right=insertnode(NULL,p,rt);
			root->rthread=0;
		}
		else
		root->right=insertnode(root->right,p,rt);
	return root;
}
예제 #12
0
int main(int argc, char const *argv[]) {
      node * head=createnodes(10);
      printf("原链表\n");
      printnodes(head);
      insertnode(head,4,100);
      printf("插入2后链表\n");
      printnodes(head);
      deletenode(head,2);
      printf("删除1后链表\n");
      printnodes(head);
      //反序输出
      printnodesf(head);
      freenodes(head);
      return 0;
}
예제 #13
0
파일: ExampleLinkedList.c 프로젝트: onano/C
int main(void) {

	int len, val;

	puts("How much Big You want your Linked List ?");
	scanf(" %d", &len);

	puts("Enter Your Elements :");
	for(int i=1; i<=len; i++) {
		scanf(" %d", &val);
		insertnode(val, i);
		printnode();
	}
	return 0;
}
예제 #14
0
void inserthash(struct hash *h,int key,char *urljodaalna,int depthjodaalni,int *totallinks)
{
	//printf("total no of links are %d\n",*totallinks);
	//printf("url jo daalna is %s\n", urljodaalna);
	//printf("hash is %s\n",h[key].head1->u.str);
	struct node *t=(struct node *)malloc(sizeof(struct node));
	t=h[key].head1;
	
	int count=h[key].countlinks;
	if(t==NULL&&count==0)
	{
		h[key].head1=insertnode(urljodaalna,depthjodaalni,key);
		(h[key].countlinks)++;	
		*totallinks=*totallinks+1;
	}
	else
	{
		//printf("xxxxxxx\n");
		while(t->next != NULL && count > 1)
		{
		//printf("****** \t");
		//printf("%s #### %s %d \n",t->u.str,urljodaalna,strcmp(t->u.str,urljodaalna));
			if(strcmp(t->u.str,urljodaalna)==0)
			{
			//printf("****url already exists in linked list****\n");
			return;
			}
			t=t->next;
			count--;
		}
			//printf("%s #### %s %d \n",t->u.str,urljodaalna,strcmp(t->u.str,urljodaalna));
		if(strcmp(t->u.str,urljodaalna)==0)
			{
			//printf("****url already exists in linked list*****\n");
			return;
			}
		//printf(" t is %d\n",t->key);
        char s[100];
		struct node *temp=createnode(urljodaalna,depthjodaalni,key);
		struct node *temp1;
		temp1=t->next;
		t->next=temp;
		temp->next=temp1;
		//printf(" t next is %s\n",t->next->u.str);
		(h[key].countlinks)++;
		*totallinks=*totallinks+1;
	}
}
예제 #15
0
int main()
{
    List *head = NULL;
    int data[10] = {1, 4, 2, 7, 9, 3, 5, 0, 8, 6};
    int i;

    for (i = 0; i < 10; i++) {
        insertnode(&head, data[i]);
    }

    printlist(head); //show data after sorting.

    releaselist(head); //free node memory.

    return 0;
}
예제 #16
0
NPTR createthreadtree()
{
	NPTR root=NULL,p;
	int temp;
	printf("pls enter elements, terminate by -99");
	scanf("%d",&temp);
	while(temp!=-99)
	{
		p=getnode();
		p->info=temp;
		p->left=p->right=NULL;
		p->rthread=0;

		root=insertnode(root,p,NULL);
		printf("enter the next element");
		scanf("%d",&temp);
	}
	return root;
}
예제 #17
0
int main(void) {

	int val, len, pos;
	printf("How Many elements you want in your Linked list? \n");
	scanf(" %d", &len);

	//Make randomisation independent of fixed system seed
	srand(time(NULL));
	for(int i=1; i<=len; i++) {
		val = rand() % 10;
		insertnode(val, i);
		printf("your list is : ");
		printnode();
	}

	puts("Enter Your Desired Position to delete");
	scanf(" %d", &pos);
	deletenode(pos);
	printf("\nyour list is  now : ");
	printnode();

	return 0;
}
void insertopen()
{
	int aa;
	int flag=0;
	int p1[3][3];
	int i,j;
	long int t=0;
	int ret=0;
	int checkclose(long int);

	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			p1[i][j]=mat[i][j];

	if(a!=0)   			//up
	{
		aa=mat[a][b];
		p1[a][b]=mat[a-1][b];
		p1[a-1][b]=aa;
		flag=1;
	}
	if(flag==1)
	{
		t=0;
		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				t=(t*10)+p1[i][j];

		ret=checkclose(t);
		if(ret==0)
			insertnode(p1);

		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				p1[i][j]=mat[i][j];
		flag=0;
	}

	if(a!=2)           		//down
	{
		aa=mat[a][b];
		p1[a][b]=mat[a+1][b];
		p1[a+1][b]=aa;
		flag=1;
	}
	if(flag==1)
	{
		t=0;
		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				t=(t*10)+p1[i][j];

		ret=checkclose(t);
		if(ret==0)
			insertnode(p1);
		t=0;
		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				p1[i][j]=mat[i][j];
		flag=0;
	}

	if(b!=0)   			//left
	{
		aa=mat[a][b];
		p1[a][b]=mat[a][b-1];
		p1[a][b-1]=aa;
		flag=1;
	}
	if(flag==1)
	{
		t=0;
		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				t=(t*10)+p1[i][j];

		ret=checkclose(t);
		if(ret==0)
			insertnode(p1);

		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				p1[i][j]=mat[i][j];
		flag=0;
	}

	if(b!=2)                        //right
	{
		aa=mat[a][b];
		p1[a][b]=mat[a][b+1];
		p1[a][b+1]=aa;
		flag=1;
	}
	if(flag==1)
	{
		t=0;
		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				t=(t*10)+p1[i][j];

		ret=checkclose(t);
		if(ret==0)
			insertnode(p1);

		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				p1[i][j]=mat[i][j];
		flag=0;
	}
}
예제 #19
0
struct dirNode* isValidPath(FileDescriptor *fd,struct dirNode* root,int *flag)
{
	int l,exitStatus;
	int index=0;
	struct dirNode *parent;
	char temp_path[MAX_FULL_PATH_SIZE],path_part[MAX_FULL_PATH_SIZE];
	char *tmp;
	char st[MAX_FULL_PATH_SIZE],prev[MAX_FULL_PATH_SIZE];
	char *tk;
	tmp=(char*)malloc(sizeof(MAX_FULL_PATH_SIZE));	
	strcpy(temp_path,fd->fullPath);
	//strcpy(path_part,parsePath(temp_path));
	tmp=parsePath(temp_path);
	//printf("\ntmp:%s\n",tmp);
	strcpy(path_part,tmp);
	if(root==NULL)
	{
		if(strcmp(path_part,"/")!=0)		//for root path
			*flag=101;			//wrong path trying to insert at root
	}
	else
	{
		exitStatus=FALSE;
		parent=root;
		while(exitStatus==FALSE)
		{
			if(strstr(path_part,parent->fileDesc->fullPath)==NULL)
			{
				if(parent->rightSibling==NULL)
				{
					if(strncmp(path_part,parent->fileDesc->fullPath,strlen(path_part)-1)!=0){
						// *flag=PATH_NOT_FOUND;
					    if(mhd.noOfFileDescriptors == MAX_NO_OF_FILE_DESCRIPTORS)
						{
							printf(ERR_VFS_MAKEDIR_01);
							*flag=401;
							return root;
						}	
						else
						{
							FileDescriptor *tempfd1=(FileDescriptor*)malloc(sizeof(FileDescriptor));
							strncpy(tempfd1->fullPath,path_part,strlen(path_part)-1);
							strcpy(st,path_part);
							tk=strtok(st,"/");
							while(tk!=NULL)
							{

								strcpy(prev,tk);
								//printf("\nprev:%s ",prev);
								tk=strtok(NULL,"/");
							}	
							
							strcpy(tempfd1->fileName,prev);
							strcpy(tempfd1->fileType,"dir");
							tempfd1->fileSize=0;
							tempfd1->locationBlockNo=-1;
							mhd.noOfFileDescriptors++;

							insertNAry(tempfd1,root,flag);
							insertBST(rootBST,tempfd1,&flag);
							index = fun_Hash(tempfd1->fileName[0]);
							array[index] = insertnode(array[index], tempfd1);
							
						}
					}
					exitStatus=TRUE;
				}
				else
						parent=parent->rightSibling;
			}
			else
			{
				if(parent->firstChild==NULL)
				{	
					if(strncmp(path_part,parent->fileDesc->fullPath,strlen(path_part)-1)!=0)
					{
						if(mhd.noOfFileDescriptors == MAX_NO_OF_FILE_DESCRIPTORS)
						{
							printf(ERR_VFS_MAKEDIR_01);
							*flag=401;
							return root;
						}		
						else
						{	
							FileDescriptor *tempfd=(FileDescriptor*)malloc(sizeof(FileDescriptor));
							strncpy(tempfd->fullPath,path_part,strlen(path_part)-1);
							strcpy(st,path_part);
							tk=strtok(st,"/");
							while(tk!=NULL)
							{
								strcpy(prev,tk);
								//printf("\nprev:%s ",prev);
								tk=strtok(NULL,"/");
							}	
							
							strcpy(tempfd->fileName,prev);
							strcpy(tempfd->fileType,"dir");
							tempfd->fileSize=0;
							tempfd->locationBlockNo=-1;	
							mhd.noOfFileDescriptors++;	

							insertNAry(tempfd,root,flag);
							insertBST(rootBST,tempfd,&flag);
							index = fun_Hash(tempfd->fileName[0]);
							array[index] = insertnode(array[index], tempfd);
	
						}							
					}
					exitStatus=TRUE;
				}	
				else
				{
					parent=parent->firstChild;
				}	
			}
		}
	   }	
     return root;		
}
예제 #20
0
int main()
{
    int n,ans,a,b;
    node* start=NULL;
    do
    {
        printf("\n---------Directed Graph------------");
        printf("\n1.Insertnode");
        printf("\n2.Insertedge");
        printf("\n3.Deletenode");
        printf("\n4.Deleteedge");
        printf("\n5.Display-nodes");
        printf("\n6.Exit\n");
        printf("\nEnter your choice:");
        scanf("%d",&ans);
        fflush(stdin);
        switch(ans)
        {
        case 1:
            printf("\nEnter the value to be inserted:");
            fflush(stdin);
            scanf("%c",&n);
            fflush(stdin);
            insertnode(&start,n);
            break;
        case 2:
            printf("\nEnter the start point of edge:");
            fflush(stdin);
            scanf("%c",&a);
            fflush(stdin);
            printf("\nEnter the end point of edge:");
            scanf("%c",&b);
            fflush(stdin);
            insertedge(start,a,b);
            break;

        case 3:
            printf("Enter the value to be deleted-->");
            fflush(stdin);
            scanf("%c",&n);
            fflush(stdin);
            delete_node(&start,n);
            break;
        case 4:
            printf("\nEnter the start point of edge:");
            fflush(stdin);
            scanf("%c",&a);
            fflush(stdin);
            printf("\nEnter the end point of edge:");
            scanf("%c",&b);
            fflush(stdin);
            delete_edge(start,a,b);
            break;
        case 5:
            printf("\nDisplaying node of the graph using breadth first traversal: \n");
            bfs_disp(start);
            break;
        case 6:
            break;
        }

    }
    while(ans!=6);
    return 0;
}