示例#1
0
//删除元素
BOOL DeleteItem(Item * pi,Tree * ptree)
{
	Pair look;

	look = SeekItem(pi,ptree);//在树中查找目标项目,成功则返回包含目标项目的父节点和当前节点的指针的结构体
	if(look.child == NULL)
	{
		return FALSE;
	}
	if(!DeQueue(pi,look.child->queue) || look.child->queue->end == NULL)//目标节点的队列为空,或删除首元素后目标节点的队列为空
	{
		if(look.parent == NULL)
		{
			DeleteNode(&ptree->root);
		}
		else if(look.parent->left == look.child)
		{
			DeleteNode(&look.parent->left);
		}
		else if(look.parent->right == look.child)
		{
			DeleteNode(&look.parent->right);
		}
		ptree->size--;
	}
	else//当前目标节点的队列不为空,删除成功
	{
		puts("Delete pet's inforamtion succesfully!");
	}
	return TRUE;
}
示例#2
0
/* Delete Nth Node from list */
void DeleteNodeNth(Node **top, int n) {
    // ここに解答を書き加える
    // nが1ならはじめの要素を消す
    if (n == 1) {
        DeleteNode(top);
        return;
    }
    Node *ptr = *top;
    int count = 1;
    while (ptr->next != NULL) {
        ptr = ptr->next;
        count++;
    }
    // nが要素数より大きい時
    if (n > count)
        return;

    if (ptr == NULL)
        return;

    ptr = *top;

    Node backup = *ptr;
    Node temp;
    int i;
    for (i = 0; i < n - 1; i++) {
        ptr = ptr->next;

        SetNode(&temp, ptr->no, ptr->name, NULL);
        SetNode(ptr, backup.no, backup.name, ptr->next);
        SetNode(&backup, temp.no, temp.name, NULL);
    }

    DeleteNode(top);
}
示例#3
0
void BinarySearchTree::DeleteNode( TreePtr & treePtr, DATA_TYPE val )
{

  if( treePtr == NULL )
    {
      return;
    }
  else if (val == treePtr->data )
    {
      DeleteNodeItem( treePtr );
    }
  else if (val < treePtr->data )
    {
      cout << "DeleteNode::treePtr->data: " << treePtr->data<< endl;
      cout < "   Looking left" << endl;
      DeleteNode (treePtr->leftPtr, val );
    }
  else 
    {
      cout << "DeleteNode::treePtr->data: " << treePtr->data << endl;
      cout << "  Looking right " << endl;
   
      DeleteNode (treePtr->rightPtr, val );  
    }
}
示例#4
0
void BinarySearchTree::DeleteNode(
                     TreePtr& treePtr, DATA_TYPE val )
{
#ifdef  DEBUG_DELETE
   cout << "DeleteNode::val:  " << val << endl;
#endif

   if( treePtr == NULL )
   {
      return;
   }
   else if( val == treePtr->data )
   {
      DeleteNodeItem( treePtr );
          //  was rootPtr---unexpected results
   }
   else if( val < treePtr->data )
   {
#ifdef  DEBUG_DELETE
      cout << "DeleteNode::treePtr->data:  " << treePtr->data << endl;
      cout << "     looking left" << endl;
#endif
      
      DeleteNode( treePtr->leftPtr, val );
   }
   else
   {
#ifdef  DEBUG_DELETE
      cout << "DeleteNode::treePtr->data:  " << treePtr->data << endl;
      cout << "     looking right" << endl;
#endif
      
      DeleteNode( treePtr->rightPtr, val );
   }
}
示例#5
0
/*
 *  Returns the full xTEDS for the corresponding xTEDS provider in Message.  A successful call to
 *  this method also frees the xTEDSSegmentNode.
 *	Params:
 *		Message - The provider with which to match the xTEDS
 *		xTEDSOut [OUTPUT] - Pointer to the buffer to store the xTEDS, this must be at least XTEDS_MAX_SIZE
 *		MaxSize - The size of xTEDSOut
 *	Returns:
 *		bool - True upon success, false is some error occurred
*/
bool xTEDSSegmentBuilder::GetFullxTEDS(const SDMxTEDS &Message, char *xTEDSOut, int MaxSize)
{
	//First, be sure that the xTEDS is fully built, and that xTEDSOut is not NULL
	if (!CheckIsFinished(Message) || xTEDSOut == NULL)
		return false;
	
	//Now we can return the xTEDS
	xTEDSSegmentNode *SegmentNode = FindNodeEntry(Message.source);
	//To be safe, see that we have the node (this should have been handled above)
	if (SegmentNode == NULL)
		return false;
	
	//Check to see that the DM's xTEDS buffer will be big enough
	if (strlen(SegmentNode->xTEDSBuffer) > static_cast<unsigned int>(MaxSize))
	{
		printf("Data Manager not built to support xTEDS of size %d (only up to %d) bytes.\n",strlen(SegmentNode->xTEDSBuffer),MaxSize);
		DeleteNode(Message.source);
		return false;
	}
	//Copy the xTEDS
	else
		strcpy(xTEDSOut, SegmentNode->xTEDSBuffer);
	
	//At this point, the xTEDS has been received, release the node
	DeleteNode(Message.source);
	
	return true;
}
示例#6
0
void CIntervalTree::ClearNode(TTreeNode* node)
{
    DeleteNodeIntervals(node->m_NodeIntervals);

    DeleteNode(node->m_Left);
    DeleteNode(node->m_Right);
    node->m_Left = node->m_Right = 0;
}
示例#7
0
void SpatialGraph::DeleteNode( SpatialGraphKDNode* pNode )
{
	if( pNode == NULL )
		return;

	DeleteNode( pNode->LHC );
	DeleteNode( pNode->RHC );

	delete pNode;
}
示例#8
0
/**
 * 习题6.45,对于二叉树中每个元素值为x的结点,删除以它为根的子树,并释放相应结点空间
 */
void DeleteNode(BiTree &T, TElemType x)
{
	if (T) {
		if (T->data == x)
			DestroyTree(T); 
		else {
			DeleteNode(T->lchild, x);
			DeleteNode(T->rchild, x);
		}
	}
}
示例#9
0
// Ö÷º¯Êý
int main(void)
{
	int pos;

	printf("TEST 1...\n");
	LinkList *plist = CreateLinkList( );				// 创建单链表
	for(int pos = 0; pos < LIST_SIZE; pos++)			// 循环向单链表中插入数据
	{
		InsertNode(plist, pos, pos + 1);
	}
	ShowList(plist);									// 插入结束后显示单链表的信息

	DeleteNode(plist, 0);								// 删除第一个元素
	ShowList(plist);
	DeleteNode(plist, 1);								// 删除第二个元素
	ShowList(plist);

	ClearLinkList(plist);								// 将单链表清空
	ShowList(plist);
	DestroyLinkList(plist);								// 将单链表销毁
	plist = NULL;

	printf("\n\nTEST 2...\n");
	LinkList list;
	InitLinkList(&list);								// 初始化单链表
	for(int pos = 0; pos < LIST_SIZE; pos++)			// 训话向单链表中插入数据
	{
		InsertNode(&list, pos, pos + 1);
	}
	ShowList(&list);									// 显示单链表
	ClearLinkList(&list);								// 清空单链表
//	FinitLinkList(&list);		// ERROR== list->m_head->m_next == NULL
	ShowList(&list);

	printf("\n\nTEST 3...\n");
	LinkListNode *prevNode = &list;			// 带头结点的单链表头指针是list->m_next
	LinkListNode *addNode = NULL;
	for(int pos = 0; pos < LIST_SIZE; pos++)
	{
		if((addNode = AddNode(&list, prevNode, pos + 1)) != NULL)
		{
            prevNode = addNode;
		}
	}
	ShowList(&list);
	while(IsEmptyLinkList(&list) != true)			// 循环删除单链表中的数据
	{
		DeleteCurrNode(&list, list.m_next);
	}
	ShowList(&list);									// 显示单链表

	return 	EXIT_SUCCESS;
}
示例#10
0
文件: z20.c 项目: 5432935/crossbridge
static void ParentFlush(BOOLEAN prnt_flush, OBJECT dest_index, BOOLEAN kill)
{ OBJECT prnt;
  debug3(DGF, DD, "ParentFlush(%s, %s, %s)",
    bool(prnt_flush), EchoIndex(dest_index), bool(kill));
  if( prnt_flush )
  { Parent(prnt, Up(dest_index));
    if( kill )  DeleteNode(dest_index);
    debug0(DGF, DD, "  calling FlushGalley from ParentFlush");
    FlushGalley(prnt);
  }
  else if( kill )  DeleteNode(dest_index)
  debug0(DGF, DD, "ParentFlush returning.");
} /* end ParentFlush */
示例#11
0
void main()
{
	cur *Cur = NULL;
	node *Node = NULL;
	InitList(&Node, &Cur);
	InsertNode(&Node, &Cur, 0, rand());
	InsertNode(&Node, &Cur, 1, rand());
	InsertNode(&Node, &Cur, 2, rand());
	DeleteNode(&Node, &Cur, 1);
	DeleteNode(&Node, &Cur, CountList(&Node, &Cur));
	DeleteNode(&Node, &Cur, 0);
 	ShowList(&Node, &Cur);
	ReleaseList(&Node, &Cur);
}
示例#12
0
bool DelItem(const Item *pi, Tree *ptree){
	Pair look;
	look = SeekItem(pi,ptree);
	if(look.child==NULL)
		return false;
	if(look.parent==NULL){ //删除根项目
		DeleteNode(&ptree->root);
	}else if(look.parent->left==look.child){
		DeleteNode(&look.parent->left);
	}else
		DeleteNode(&look.parent->right);
	ptree->items--;
	return true;
}
示例#13
0
/*
 * Free up a trace's mallocs...
 */
void FreeTrace(Trptr t)
{
if(straces)
	{
	struct strace_defer_free *sd = calloc_2(1, sizeof(struct strace_defer_free));
	sd->next = strace_defer_free_head;
	sd->defer = t;

	strace_defer_free_head = sd;
	return;
	}

if(t->vector)
      	{
      	bvptr bv;
	int i;

	bv=t->n.vec;
	for(i=0;i<bv->numregions;i++)
		{
		if(bv->vectors[i]) free_2(bv->vectors[i]);
		}
	
	if(bv->bits)
		{
		if(bv->bits->name) free_2(bv->bits->name);
		for(i=0;i<bv->nbits;i++)
			{
			DeleteNode(bv->bits->nodes[i]);
			}
		free_2(bv->bits);
		}

	if(bv->name) free_2(bv->name);
      	if(t->n.vec)free_2(t->n.vec);
      	}
	else
	{
	if(t->n.nd && t->n.nd->expansion)
		{
		DeleteNode(t->n.nd);
		}
	}

if(t->asciivalue) free_2(t->asciivalue);
if((t->is_alias)&&(t->name)) free_2(t->name);

free_2( t );
}
示例#14
0
int main( void )
{
  List *list = CreateList( );
  node *n;

  int x = 17;
  int y = 18;
  int z = 19;

  InsertFront( list, &x, sizeof( int ) );
  InsertFront( list, &y, sizeof( int ) );
  InsertFront( list, &z, sizeof( int ) );

  // Loop through list. It's important to use ListBegin and ListEnd for proper looping.
  // Make note of what pointers Begin and End return.
  for(n = ListBegin( list ); n != ListEnd( list ); n = n->next)
    printf( "%d\n", NODE_DATA( n, int ) );

  // Proper way to delete nodes from list is like so:
  // note -- we are not doing n = n->next within the for loop, instead
  //         we use the return value of delete
  for(n = ListBegin( list ); n != ListEnd( list );)
    n = DeleteNode( list, n );

  getchar( );

  return 0;
}
示例#15
0
// ******************************************************************
// Löscht einen Octree-Knoten rekursiv
tbResult tbOctree::DeleteNode(tbOctreeNode* pNode)
{
    // Ist es ein Endknoten? Wenn ja, werden seine Daten gelöscht.
    if(pNode->bIsLeaf)
    {
        TB_SAFE_MEMFREE(pNode->pdwEffectStart);
        TB_SAFE_MEMFREE(pNode->pdwEffectEnd);
        TB_SAFE_MEMFREE(pNode->pdwMinIndex);
        TB_SAFE_MEMFREE(pNode->pdwMaxIndex);

        if(m_bExtraData)
        {
            TB_SAFE_MEMFREE(pNode->pTrianglePlanes);
            TB_SAFE_MEMFREE(pNode->pdwIndices);
        }
    }
    else
    {
        // Die 8 untergeordneten Knoten rekursiv löschen
        for(DWORD i = 0; i < 8; i++) DeleteNode(pNode->apChild[i]);
    }

    // Den Knoten selbst löschen
    TB_SAFE_MEMFREE(pNode);

    return TB_OK;
}
示例#16
0
文件: books.c 项目: yuvalg/HW18-FINAL
/* Function to remove a book from book DB */
void RemoveBook(char *id, book_db *db_head){
	book *removedBook;
	int removeResult;

	/* Find the book that we want to remove */
	removedBook=GetBook(id, db_head);

	/* If book not found print an error and stop function */
	if (removedBook==NULL){
		printf("The book %s was not found in the library inventory\n",id);
		return;
	}

	/* Make sure that no customer has the book out on loan */
	if (removedBook->customers->first==NULL){
		/* Use generic RemoveNode command to remove the book from the DB */
		removeResult=DeleteNode(id,db_head->books);
		if (removeResult==FAIL)
			printf("Error - Could not delete book\n");
		return;
	}

	printf("Can not delete book from inventory, %d copies are still out on loan.\n",removedBook->loans);
	return;
}
示例#17
0
/*
 * CloseCurrentImage - Gets the current image the user is editing and deletes
 *                     the node from the linked list and sends a message to
 *                     destroy the mdi child (this will activate another
 *                     child then).
 */
void CloseCurrentImage( HWND hwnd )
{
    img_node    *node;
    char        file_name[ _MAX_PATH ];
    BOOL        ret;

    node = SelectImage( hwnd );
    if (!node) return;
    ret = DestroyWindow( _wpi_getframe(node->viewhwnd) );
    GetFnameFromPath( node->fname, file_name );
    DeleteUndoStack( hwnd );
    if ( !DeleteNode(hwnd) ) {
        WImgEditError( WIE_ERR_BAD_HWND, WIE_INTERNAL_002 );
        return;
    }
    DeleteActiveImage();
    ClearImageText();

    GrayEditOptions();
    PrintHintTextByID( WIE_FILEHASBEENCLOSED, file_name );
    SetWindowText( _wpi_getframe(HMainWindow), IEAppTitle );

#ifdef __OS2_PM__
    ret = DestroyWindow( _wpi_getframe(hwnd) );
#else
    SendMessage(ClientWindow, WM_MDIDESTROY, (WPARAM)hwnd, 0L);
#endif
} /* CloseCurrentImage */
 ListNode *partition(ListNode *head, int x) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     ListNode* n_it=head, *prevLess=NULL, *prev=NULL, *temp; // when first node >= x
     while(n_it!=NULL){            
         if( n_it->val>=x){
             prev=n_it;
             n_it=n_it->next;
         }
         else{                   // prev won't change
             temp=n_it;          // point to the current node
             n_it=n_it->next;    // iterator to the next node
             DeleteNode(prev,temp);
             if(prev==NULL){ // this node is the first node
                 prevLess=temp;
                 continue;
             }
             else if(prevLess==NULL){
                 temp->next=head;
                 head=temp;
                 prevLess=head;
             }
             else
                 prevLess=Insert(prevLess,temp);
                       
         }        
     }
     return head;
 }       
示例#19
0
void Vector::remove(int index)
{
   if(VectorSize == 0)
     return;
   if(index > VectorSize)
     return;

   if(VectorSize - 1 == 0)
     {
	clear();
	return;
     }

   VectorNode ** NewArray = (VectorNode **) new void*[sizeof(VectorNode *)*(VectorSize - 1)];

   int a, b;
   a = b = 0;
   for(a = 0; a < VectorSize; a++)
     {
	if(a == index)
	  {
	     DeleteNode(Array[a]);
	     a++;
	  }
	NewArray[b] = Array[a];
	b++;
     }
   delete Array;
   Array = NewArray;
   VectorSize--;
   ReCount();
}
示例#20
0
void CTreeWnd::DeleteAllNodes()
{
	if (!m_pTree)
		return;

    m_selection.Clear();

	// clear all nodes
	mtNode* pRoot = m_pTree->getRoot();
    if (pRoot)
    {
        DeleteNode(pRoot);
        CTreeNode* pTN = (CTreeNode*)pRoot->getData2();
        delete pTN;
    }
    m_pTree->removeAll();
    m_firstVisible = NULL;

	SetScrollPos32(SB_VERT,0);
	SetScrollPos32(SB_HORZ,0);


    ForceLayout();
    Invalidate();
}
示例#21
0
/* put a new node in frequecy 1 queue, and update the hash table */
void LFUCache::PutNode(int frameid, int value) {
    LFUListNode* listnode = new LFUListNode(frameid, value);
    if(!Free)
        DeleteNode();
        
    /* case 1: if Head->next is the frequency 1 node*/
    if (FreqHead->Next && FreqHead->Next->Freq == 1) 
	InsertNode(listnode, FreqHead->Next);
		
    /* case 2: if Head is null || case 3: if Head->next is not the frequency 1 node*/
    else {
	FreqNode* nextfreq = new FreqNode(1);
	/* connect frequency node */
	if(FreqHead->Next) {
	    nextfreq->Next =  FreqHead->Next;
	    FreqHead->Next->Prev = nextfreq;
	}
	FreqHead->Next = nextfreq;
	nextfreq->Prev = FreqHead;
	InsertNode(listnode, nextfreq);
	cout<<listnode<<endl;
    }    
	
    /* insert to hash table */
    LFUHash.insert({frameid, listnode});
    Free--;
    return;
}
示例#22
0
void ExecuteCommand(nodeT **t,char command,int key)
{
   /* printf("\nExcuteCommand Hit here\n");*/
    double i;
		int h;
		int count;

    switch (toupper(command)) {
        case 'I': InsertNode(t, key);break;
        case 'D': printf("\n");DeleteNode(t, key);printf("\n"); break;
        case 'F': printf("\n");FindNode(*t,key);printf("\n"); break;
        case 'O': printf("\n");ListInOrder(*t); printf("\n");break;
        case 'P': printf("\n");PreOrderWalk(*t);printf("\n"); break;
        case 'A': printf("\n");PostOrderWalk(*t);printf("\n"); break;
        case 'L': printf("\n");NodeLevelOrder(*t);printf("\n"); break;
        case 'S': printf("\n");i=add(*t);printf("Sum of tree is:%f\n",i); break;
        case 'N': printf("\n");printf("Min:");Min(*t); printf("\n");break;
        case 'X': printf("\n");printf("Max:");Max(*t); printf("\n");break;
        case 'T': printf("\n");h=height(*t); printf("Height:%d\n",h);break;
        case 'C': printf("\n");count=Count(*t); printf("Number of inputs is:%d\n",count);break;
        case 'H': printf("\n");HelpCommand(); printf("\n");break;
        case 'Q': free_all(*t);exit(0);
        default:  printf("Illegal command\n"); break;
    }
}
示例#23
0
global void KillAllSounds() {
	Sound		*sn;
	Handle	theHandle;

	/* Stop and delete each node in the sound list
	 */

	while(!EmptyList(&soundList)) {
		sn = (Sound *) Native(FirstNode(&soundList));
		if (sn->sSample) {
			audArgs.count = 2;
			audArgs.func = STOP;
			audArgs.arg2 = sn->sNumber;
			KDoAudio ((word *)&audArgs);
		}
		else {
			DoSound(SEnd,(char far *) sn);
			ResLock(RES_SOUND,sn->sNumber,FALSE);
			if(theHandle = (Handle)
				Native(GetProperty((Obj *) Native(sn->sKey), s_handle))) {
if ((int)theHandle != 1)
{
				CriticalHandle(theHandle,FALSE);
				UnlockHandle(theHandle);
}
			}
		}
		DeleteNode(&soundList,Pseudo(sn));
	}
}
 ListNode *deleteDuplicates(ListNode *head) {
     if(head == NULL)
     {
         return NULL;
     }
     ListNode dummy(0);//构造虚拟节点,简化对链表头的处理
     dummy.next = head;
     ListNode *p_ahead = &dummy;
     ListNode *p_behind = dummy.next;
     while(p_behind != NULL && p_behind->next != NULL) //p_behind != NULL 是为处理链表的末尾为重复元素
     {
         if(p_ahead->next->val != p_behind->next->val) //注意判断的是值
         {
             p_ahead = p_ahead->next;
             p_behind = p_behind->next;
         }
         else
         {   //p_behind->next != NULL 是为处理链表的末尾为重复元素
             while(p_behind->next != NULL && p_ahead->next->val == p_behind->next->val)
             {
                  p_behind = p_behind->next;
             }
             ListNode *p_tmp = p_ahead->next;
             p_ahead->next = p_behind->next;
             p_behind->next = NULL;
             p_behind = p_ahead->next;
             DeleteNode(p_tmp);
         }
     }
     return dummy.next;
 }
示例#25
0
/**
 *  Deletes a node in a given tree's node index.
 *
 *  @param  index   Index of the node to be deleted.
 */
void VDFTree::DeleteNode(UINT index)
{
    if(index < nodeCount) {
        if(nodeIndex[index])
            DeleteNode(nodeIndex[index]);
    }
}
示例#26
0
/**
void ClearCirLinkList(CirLinkList *list)
参数
	list	:	指向一个链表指针,此处传入表头地址
返回值
	无
功能
	清空单链表中的所有元素
*/
void ClearCirLinkList(CirLinkList *list)
{
	while(list->m_head->m_next != list->m_head)
	{
        DeleteNode(list, 0);
	}
}
示例#27
0
int main()
{ 
FILE *fp = NULL; 
List list; 
String string; 
int i; 
int records = 0; 
char filename[100];
//list.Head = (ListNode*)malloc(sizeof(ListNode)); 
list.Head = NULL; 
string.str = (char *)malloc(sizeof(char) *20); 
printf("Enter filename\n"); 
scanf("%s", filename); 
fp = fopen(filename, "r"); 

if (fp == NULL) 
{ printf ("Error\n"); 
exit(0); 
}
else 
{
fscanf(fp, "%d", &records);
for (i = 0; i<records; i++) 
{
fscanf(fp, "%s", string.str);
AddNode(&list, string);
printf("%s  ", string.str);
}
printf("\n\nEnter a Node to delete: ");
scanf("%s", string.str);
DeleteNode(&list, string);
}
return 1;
}
int main()
{
	struct DLLNode *head;
	int a,i,p;
	head = NULL;
	while(1)
	{
		printf("Enter Your choice: \n 1. insert \n 2. Delete Node \n");
		scanf("%d" , &a);
		switch(a)
		{
			case 1:
			printf("Enter the number and the position that you want to enter a\n");
			scanf("%d %d \n", &i, &p);
			
			insert(i,p);
			break;
			case 2:
			printf("Enter the position from which you want to delete the node \n");
			scanf("%d", &p);
			DeleteNode(p);
			default:
			printf("Wrong choice \n");
			return 0;
			break;

		}
	}
	return 0;
}
示例#29
0
void test1()
{
	int data[] = {35, 6, 15, 65, 7, 46, 17, 43, 3, 7};
//	int data[] = {3};
	int size = sizeof(data)/sizeof(*data);
//	printf("size = %d\n", size);
	BSTree BST = NULL;
	BuildBSTree(BST, data, 0, size - 1);
	PreOrderTraverse(BST);
	printf("\n");
	MidOrderTraverse(BST);
	printf("\n");
	PostOrderTraverse(BST);
	printf("\n");

	BSTree node = SearchBST(BST, 17, 0);
	if (!node)
		printf("Search failed.\n");
	else
		printf("Search success, the search value is %d.\n", node->value);

	int n;
	scanf("%d", &n);
	while (n != -1)
	{
		DeleteNode(BST, n);
//		printf("Delete node %d.\n", n);
		MidOrderTraverse(BST);
		printf("\n");
		scanf("%d", &n);
	}

	printf("\n");
	
}
示例#30
0
void main()
{
    struct Node item0, item1, item2, item3;        

    item0.value = 90;
    item0.next = &item1;

    item1.value = 100;
    item1.next = &item2;

    item2.value = 110;
    item2.next = &item3;

    item3.value = 120;
    item3.next = NULL;
    
    printf("The initial list is....\n");
    DisplayList(&item0);
    
    printf("After deleting the 3rd item, the list is...\n");
    DeleteNode(&item0, &item2);
    DisplayList(&item0);
    
    printf("After adding the previously deleted 3rd item at the last location..\n");
    InsertNode(&item3, &item2);
    DisplayList(&item0);
}