示例#1
0
void CreatelinkList(Node **pHead,char *word)  
{  
    if(*pHead==NULL)  
        *pHead=AddNewNode(word);  
    else  
    {  
        Node *p=*pHead;  
        while(p->pNext!=NULL) p=p->pNext;  
        p->pNext=AddNewNode(word);  
    }  
}  
示例#2
0
int HuffmanCoDec::DecodeSymbol()
{
	int currentNode;
	int nextSymbol;

	currentNode = iROOT_NODE;
	while( nodes[ currentNode ].iChildIsLeaf == FALSE )
	{
		currentNode = nodes[ currentNode ].iChild;
		currentNode += bitBuffer.GetBit();
	}

	nextSymbol = nodes[ currentNode ].iChild;
	if ( nextSymbol == iESCAPE )
	{
		nextSymbol = ( int )bitBuffer.GetBits( 8 );
		AddNewNode( nextSymbol );
	}

#ifdef _DEBUG
	VerifyTree();
#endif

	return nextSymbol;
}
示例#3
0
void HuffmanCoDec::EncodeSymbol( int nextSymbol )
{
	DWORD code;
	DWORD currentBit;
	int codeSize;
	int currentNode;

	code = 0;
	currentBit = 1;
	codeSize = 0;
	currentNode = iLeaf[ nextSymbol ];

	if ( currentNode == -1 )
		currentNode = iLeaf[ iESCAPE ];

	while( currentNode != iROOT_NODE )
	{
		if ( ( currentNode & 1 ) == 0 )
			code |= currentBit;
		currentBit <<= 1;
		codeSize++;
		currentNode = nodes[ currentNode ].iParent;
	}

	bitBuffer.PutBits( code, codeSize );
	if ( iLeaf[ nextSymbol ] == -1 )
	{
		bitBuffer.PutBits( ( DWORD )nextSymbol, 8 );
		AddNewNode( nextSymbol );
	}

#ifdef _DEBUG
	VerifyTree();
#endif
}
示例#4
0
/*************createlist**************/
void CreateList(FILE *fp, My402List *List)
{
    char buf[1027];

    while(fgets(buf, sizeof(buf), fp) != NULL)
     {
        //printf("%d\n",num_line);
        /* buf may contain '\n' */
        //check length
        if(strlen(buf) > 1024)
            ExitAll(" format err: the line is too long",0);//exit
        //create new node~(success not sure)

        AddNewNode(buf, List);

        //My402ListElem *test;
        //test = My402ListLast(List);

        //printf("%s%d%s%s\n", ((My402ListElemObj*)test->obj)->TSign,((My402ListElemObj*)test->obj)->TTime,((My402ListElemObj*)test->obj)->TAm,((My402ListElemObj*)test->obj)->TDesc);

        //printf("the length of my402list is %d\n", My402ListLength(List));
        //printf("it is empty? %d\n", My402ListEmpty(List));
        //printf("%s", buf);
    }
}
示例#5
0
/////////////////////////////////////////////////////////////////////////
// 이름을 입력받아 리스트에 추가하는 함수
void Add()
{
	char szName[32] = { 0 };
	char szPhone[32] = { 0 };

	printf("Input name : ");
	fflush(stdin);
	gets_s(szName, sizeof(szName));

	printf("Input phone number : ");
	fflush(stdin);
	gets_s(szPhone, sizeof(szPhone));

	// 실제로 리스트에 추가한다.
	AddNewNode(szName, szPhone);
}
示例#6
0
/////////////////////////////////////////////////////////////////////////
// 데이터 파일에서 노드들을 읽어와 리스트를 완성하는 함수
int LoadList(char *pszFileName)
{
	FILE *fp = NULL;
	USERDATA user = { 0 };

	fopen_s(&fp, pszFileName, "rb");

	if (fp == NULL)
		return 0;

	ReleaseList();

	while (fread(&user, sizeof(USERDATA), 1, fp))
		AddNewNode(user.szName, user.szPhone);

	fclose(fp);

	return 0;
}