Пример #1
0
struct tnode *findLastNodeOrOneChildNode(struct tnode *p,int isBeforeReduceCount){//2번째 인자는 빈도를 줄인시점부터 함수를 호출했는지 이후에 호출해줬는지 명시해주는 bool값
    struct tnode *tmp = NULL;
    if(p!=NULL){
        tmp = findLastNode(p->left,isBeforeReduceCount);
        if(tmp==NULL){
            if(isBeforeReduceCount==1){
                if(p->count>1&&((p->left==NULL&&p->right==NULL)||(p->left!=NULL&&p->right==NULL)||(p->left==NULL&&p->right!=NULL))){
                    tmp = p;
                    return tmp;
                }
            }
            else{
                if(p->count>0&&((p->left==NULL&&p->right==NULL)||(p->left!=NULL&&p->right==NULL)||(p->left==NULL&&p->right!=NULL))){
                    tmp = p;
                    return tmp;
                }
            }
        }
        if(tmp==NULL){
            tmp = findLastNode(p->right,isBeforeReduceCount);
        }
    }
    return tmp;
}
Пример #2
0
int main()
{
	int i;
	LINKED_LIST myListHead=getNode();
	myListHead->next=NULL;

	for(i=0;i<10;i++)
	{
		LINKED_LIST tempNode=getNode();
		tempNode->key=i;
		insertAtHead(myListHead,tempNode);
	}


	printLinkedList(myListHead);


	LINKED_LIST searchElement;
	searchElement=getNode();

	searchElement=listSearch(myListHead,4);	

	printf("\n\nSearchedElement:%d\n",searchElement->key);

	LINKED_LIST lastNode;
	searchElement=getNode();

	searchElement=findLastNode(myListHead);	

	printf("\n\nLastNode:%d\n",searchElement->key);


	LINKED_LIST toDeleteElement;
	toDeleteElement=getNode();
	toDeleteElement=listSearch(myListHead,6);
	int deletedElement=deleteNode(myListHead,toDeleteElement);
	
	printf("\nElementDeleted=%d\n",deletedElement);	
	printLinkedList(myListHead);
	


	return 0;
}