コード例 #1
0
ファイル: AVL_TREE.c プロジェクト: helloqiu/dataClass
static Node NodeDelete(Node rootnode , Node delnode){
    if (delnode == NULL || rootnode == NULL){
        return NULL;
    }
    //node in the left
    if (delnode -> data < rootnode -> data){
        rootnode -> left = NodeDelete(rootnode -> left , delnode);
        //lose balance
        if (Height(rootnode -> right) == Height(rootnode -> right) + 2){
            Node right = rootnode -> right;
            if (Height(right -> left) > Height(right -> right)){
                rootnode = RL(rootnode);
            }else{
                rootnode = RR(rootnode);
            }
        }
    }
    //node in the right
    if (delnode -> data > rootnode -> data){
        rootnode -> right = NodeDelete(rootnode -> right , delnode);
        //lose balance
        if (Height(rootnode -> left) == Height(rootnode -> right) + 2){
            Node left = rootnode -> left;
            if (Height(left -> right) > Height(left -> left)){
                rootnode = LR(rootnode);
            }else{
                rootnode = LL(rootnode);
            }
        }
    }
    //delnode is rootnode
    if (delnode -> data == rootnode -> data){
        if ((rootnode -> left != NULL) && (rootnode -> right != NULL)){
            //left is lager than right
            if (Height(rootnode -> left) > Height(rootnode -> right)){
                Node max = FindMax(rootnode -> left);
                rootnode -> data = max -> data;
                rootnode -> left = NodeDelete(rootnode -> left , max);
            }else{
            //right is lager than left
                Node min = FindMin(rootnode -> right);
                rootnode -> data = min -> data;
                rootnode -> right = NodeDelete(rootnode -> right , min);
            }
        }else{
        //left || right in null
            Node tmp = rootnode;
            if (rootnode -> left != NULL){
                rootnode = rootnode -> left;
            }else{
                rootnode = rootnode -> right;
            }
            free(tmp);
        }
    }
    return rootnode;
}
コード例 #2
0
ファイル: settings.c プロジェクト: BigHNF/tcpmp-revive
static int Done(settings* p)
{
	if (p->Win.Flags & WIN_PROP_SOFTRESET)
		ShowMessage(LangStr(SETTINGS_ID,NODE_NAME),LangStr(SETTINGS_ID,SETTINGS_SOFTRESET));
	else
	if (p->Win.Flags & WIN_PROP_RESTART)
		ShowMessage(LangStr(SETTINGS_ID,NODE_NAME),LangStr(SETTINGS_ID,SETTINGS_RESTART));

	if (p->Win.Flags & WIN_PROP_RESYNC)
	{
		player* Player = (player*)Context()->Player;
		if (Player)
			Player->Set(Player,PLAYER_RESYNC,NULL,0);
	}

	if (p->Win.Flags & WIN_PROP_CHANGED)
	{
		p->Win.Flags &= ~WIN_PROP_CHANGED;
#ifdef REGISTRY_GLOBAL
		NodeRegSaveGlobal();
#else
		if (p->Current)
			NodeRegSave(p->Current);
#endif
	}

	NodeDelete(p->Current);
	p->Current = NULL;
	return ERR_NONE;
}
コード例 #3
0
void SuppThread::run()
{
    QString pathfile = QDir::home().path()+"/AppData/Roaming/FileZilla/sitemanager.xml";

     // convert QString to const char
     TiXmlDocument doc(pathfile.toStdString().c_str());

     if(!doc.LoadFile())
     {
         emit isErrorXml(0);
         return;
     }

     TiXmlHandle hdl(&doc);

     // Go to the "Server" Node
     TiXmlElement *elem = hdl.FirstChildElement().FirstChildElement().FirstChildElement().Element();
     TiXmlElement *rootServer = hdl.FirstChildElement().FirstChildElement().Element();

     if(!elem){
         emit isErrorXml(1);
         return;
     }

     // Parse all "Server" Node to find the node witch will be delete
     bool find = false;
     bool isDelete = false;
     while ( elem )
     {
         if ( QString(elem->FirstChildElement("Name")->GetText()) == node )
            find = true;

         if ( QString(elem->FirstChildElement("Comments")->GetText()).isEmpty() )
             elem->FirstChildElement("Comments")->LinkEndChild(new TiXmlText(""));

         if ( QString(elem->FirstChildElement("LocalDir")->GetText()).isEmpty() )
             elem->FirstChildElement("LocalDir")->LinkEndChild(new TiXmlText(""));

         if ( QString(elem->FirstChildElement("RemoteDir")->GetText()).isEmpty() )
             elem->FirstChildElement("RemoteDir")->LinkEndChild(new TiXmlText(""));

         if ( find )
         {
             if ( rootServer->RemoveChild(elem) )
                 isDelete = true;

             emit NodeDelete(isDelete);
             doc.SaveFile();
             break;
         }

         elem = elem->NextSiblingElement();
     }

     qDebug()<<"Thread delete is Out"<<endl;

    return;
}
コード例 #4
0
int main(int argc,char** argv)
{
    node* p[10000];
    int i;
    nodecontext Context;
    NodeContext_Init(&Context,NULL,NULL,NULL);

    for (i=0;i<10000;++i)
        p[i] = NodeCreate(&Context,NODE_CLASS);

    for (i=0;i<1000000;++i)
        NodeDelete(NodeCreate(&Context,NODE_CLASS));

    for (i=0;i<10000;++i)
        NodeDelete(p[i]);

    NodeContext_Done(&Context);
    return 0;
}
コード例 #5
0
ファイル: list.cpp プロジェクト: jazzboysc/RTGI
void  ListDestruct(Node ** root  )
{
	 Node * tn;


	 while( *root ){
	 tn = (*root);
	 NodeDelete(root,&tn);
	 }

}
コード例 #6
0
ファイル: abp.c プロジェクト: pbmartins/AlgC
void ABPDeleteRec (PtABPNode *proot, int pelem)	/* remoção recursiva - recursive deletion */
{
	Error = OK;
	if (*proot == NULL) { Error = NO_ELEM; return; }	/* arvore vazia ou elemento inexistente - empty tree or non existing element */

	if ((*proot)->Elem > pelem)
			ABPDeleteRec (&(*proot)->PtLeft, pelem);
	else if ((*proot)->Elem < pelem)
				ABPDeleteRec (&(*proot)->PtRight, pelem);
			else NodeDelete (proot);	/* eliminar o elemento - deleting the element */
}
コード例 #7
0
ファイル: avl.c プロジェクト: diogofferreira/AlgC
void AVLDeleteRec (PtAVLNode *proot, int pelem)	/* recursiva */
{
	if (*proot == NULL) { Error = NO_ELEM; return; }	/* arvore vazia ou elemento inexistente */

	if ((*proot)->Elem > pelem)
			AVLDeleteRec (&(*proot)->PtLeft, pelem);
	else	if ((*proot)->Elem < pelem)
				AVLDeleteRec (&(*proot)->PtRight, pelem);
			else { Error = OK; NodeDelete (proot); }

	Balance (proot);	/* reequilibrar a árvore */
}
コード例 #8
0
ファイル: StructureElement.cpp プロジェクト: nutofem/nuto
void NuTo::Structure::ElementGroupDelete(int rGroupNumber, bool deleteNodes)
{
    Timer timer(__FUNCTION__, GetShowTime(), GetLogger());

    boost::ptr_map<int, GroupBase>::iterator itGroup = mGroupMap.find(rGroupNumber);
    if (itGroup == mGroupMap.end())
        throw Exception(__PRETTY_FUNCTION__, "Group with the given identifier does not exist.");
    if (itGroup->second->GetType() != NuTo::eGroupId::Elements)
        throw Exception(__PRETTY_FUNCTION__, "Group is not an element group.");

    // the group has to be copied, since the elements are removed from this group, which invalidates the iterators
    Group<ElementBase> copyOfElementGroup = Group<ElementBase>(*(itGroup->second->AsGroupElement()));

    std::set<NodeBase*> potentialNodesToBeRemoved;
    for (auto& elementPtr : copyOfElementGroup)
    {
        // save the nodes, which are eventually to be removed
        if (deleteNodes)
        {
            for (int countNode = 0; countNode < elementPtr.second->GetNumNodes(); countNode++)
            {
                NodeBase* nodePtr = elementPtr.second->GetNode(countNode);
                potentialNodesToBeRemoved.insert(nodePtr);
            }
        }
        ElementDeleteInternal(ElementGetId(elementPtr.second));
    }

    // check all the other elements and see, if they have one of the potential Nodes To Be Removed as valid node
    for (boost::ptr_map<int, ElementBase>::iterator itElement = mElementMap.begin(); itElement != mElementMap.end();
         itElement++)
    {
        for (int countNode = 0; countNode < (itElement->second)->GetNumNodes(); countNode++)
        {
            NodeBase* nodePtr = (itElement->second)->GetNode(countNode);
            // int numRemoved = potentialNodesToBeRemoved.erase(nodePtr);
            potentialNodesToBeRemoved.erase(nodePtr);
        }
    }

    std::map<NodeBase*, int> nodeToId;
    for (auto it = mNodeMap.begin(); it != mNodeMap.end(); ++it)
        nodeToId[it->second] = it->first;

    for (auto node : potentialNodesToBeRemoved)
    {
        int nodeId = nodeToId[node];
        NodeDelete(nodeId, false);
    }
}
コード例 #9
0
ファイル: list.cpp プロジェクト: jazzboysc/RTGI
int ListDeleteNode( Node ** root, void * pointer, int type ){

  Node * node = (*root);

  if( node )
    do{
      if( node->p == pointer && node->type == type ){
	NodeDelete( root, &node );
	return 1;
      }
      node = node->next;
    }while( node != (*root) );

  return 0;
}
コード例 #10
0
ファイル: menu.c プロジェクト: TheCodeJanitor/collisionWM
void RemoveMenuBottomLines(Menu *men)
{
  Node *n;
  if((n=NodePrev(men->Items,NULL))&&(((MenuItem *)(n->data))->type == I_LINE)) {
    free(n->data);
    NodeDelete(men->Items,n);
    men->height-=2*MENUBORDERW;
    XResizeWindow(disp,men->win,men->width,men->height);
  }
  n=NULL;
  while((n=NodeNext(men->Items,n))){
    MenuItem *mi;
    mi=n->data;
    if(mi->type==I_SUBMENU) RemoveMenuBottomLines(mi->data);
  }
}
コード例 #11
0
ファイル: parsertest.c プロジェクト: ekoeppen/kino-2
void main (int argc, char *argv[])
{
  Parser *p;
  Document *d;
  char *t;
  char *text;
  int h;
  struct stat stats;

  d = DocumentNew ();
  d->root = ElementNew ();
  d->root->anonymous = ANON_BOX;
  d->root->document = d;
  DocumentAddTagHandler (d, tagHandler, NULL);
  DocumentAddLinkHandler (d, linkHandler, NULL);

  p = ParserNew ();
  p->document = d;
  p->startElement = d->root;
  if (argc > 1)
  {
    lstat (argv[1], &stats);
    text = malloc (stats.st_size + 1);
    h = open (argv[1], O_RDONLY);
    read (h, text, stats.st_size);
    close (h);
    text[stats.st_size] = '\0';
  }
  else
  {
    text = XkNewString ("<h1>Hello World <![CDATA[Hello, world]]></h1>");
  }
  ParserProcessData (p, "text/html", text);
  free (text);

  NodePrint (d->root, 0);

  t = NodeToText (d);
  puts (t);
  free (t);
  NodeDelete ((Node *) d);
  ParserDelete (p);
}
コード例 #12
0
filepos_t EBML_VoidReplaceWith(ebml_element *Void, ebml_element *ReplacedWith, stream *Output, bool_t ComeBackAfterward, bool_t bWithDefault)
{
    filepos_t CurrentPosition;
    assert(Node_IsPartOf(Void,EBML_VOID_CLASS));

	EBML_ElementUpdateSize(ReplacedWith,bWithDefault,0);
	if (EBML_ElementFullSize(Void,1) < EBML_ElementFullSize(ReplacedWith,1))
		// the element can't be written here !
		return INVALID_FILEPOS_T;
	if (EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1) == 1)
		// there is not enough space to put a filling element
		return INVALID_FILEPOS_T;

	CurrentPosition = Stream_Seek(Output,0,SEEK_CUR);

    Stream_Seek(Output,Void->ElementPosition,SEEK_SET);
    EBML_ElementRender(ReplacedWith,Output,bWithDefault,0,1,NULL);

    if (EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1) > 1)
    {
        // fill the rest with another void element
        ebml_element *aTmp = EBML_ElementCreate(Void,Void->Context,0,NULL);
        if (aTmp)
        {
            filepos_t HeadBefore,HeadAfter;
            EBML_VoidSetFullSize(aTmp, EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1));
            HeadBefore = EBML_ElementFullSize(aTmp,1) - aTmp->DataSize;
            aTmp->DataSize = aTmp->DataSize - EBML_CodedSizeLength(aTmp->DataSize, aTmp->SizeLength, EBML_ElementIsFiniteSize(aTmp));
            HeadAfter = EBML_ElementFullSize(aTmp,1) - aTmp->DataSize;
            if (HeadBefore != HeadAfter)
                aTmp->SizeLength = (int8_t)(EBML_CodedSizeLength(aTmp->DataSize, aTmp->SizeLength, EBML_ElementIsFiniteSize(aTmp)) - (HeadAfter - HeadBefore));
            EBML_ElementRenderHead(aTmp,Output,0,NULL);
            NodeDelete((node*)aTmp);
        }
    }

	if (ComeBackAfterward)
        Stream_Seek(Output,CurrentPosition,SEEK_SET);

	return EBML_ElementFullSize(Void,1);
}
コード例 #13
0
ファイル: streams.c プロジェクト: robUx4/ResInfo
stream* StreamOpen(anynode *AnyNode, const tchar_t* Path, int Flags)
{
	stream* File = GetStream(AnyNode,Path,Flags);
	if (File)
	{
		err_t Err = Stream_Open(File,Path,Flags);
        if (Err != ERR_NONE && Err != ERR_NEED_MORE_DATA)
		{
			NodeDelete((node*)File);
			File = NULL;
		}
        else
        {
            stream* Buf;
            if ((Flags & SFLAG_BUFFERED) && (Buf = (stream*)NodeCreate(AnyNode,BUFSTREAM_CLASS)) != NULL)
            {
                Node_SET(Buf,BUFSTREAM_STREAM,&File);
                File = Buf;
            }
        }
	}
	return File;
}
コード例 #14
0
ファイル: settings.c プロジェクト: BigHNF/tcpmp-revive
static void UpdatePage(settings* p)
{
	datadef DataDef;
	node* Node;
	bool_t Found = 0;
	int Class = Context()->SettingsPage;
	int No,i;
	winunit y;
	bool_t CheckList;
	tchar_t Data[MAXDATA/sizeof(tchar_t)];

#ifndef REGISTRY_GLOBAL
	if (p->Win.Flags & WIN_PROP_CHANGED)
	{
		p->Win.Flags &= ~WIN_PROP_CHANGED;
		if (p->Current)
			NodeRegSave(p->Current);
	}
#endif

	WinBeginUpdate(&p->Win);

	for (No=0;No<p->Count;++No)
	{
		if (p->Node[No]==Class)
			Found = 1;
		WinMenuCheck(&p->Win,p->Menu,SETTINGS_PAGES+No,p->Node[No]==Class);
	}

	if (!Found && p->Count>0)
		Class = p->Node[0];
	
	NodeDelete(p->Current);
	p->Current = Node = NodeCreate(Class);
	
	if (Node)
	{
		WinTitle(&p->Win,LangStr(Class,NODE_NAME));

		p->Win.LabelWidth = 
			(Class == PLATFORM_ID) ? 60:
			(p->Win.ScreenWidth < 130) ? 80:
			(Class == PLAYER_ID || Class == ADVANCED_ID) ? 120:90;

		CheckList = Class == ASSOCIATION_ID;
		y = 2;

		// if the menu is in bottom of screen. print a hint before platform settings (first page shown)
		if (Class == PLATFORM_ID && (p->Win.Flags & WIN_BOTTOMTOOLBAR) && !(p->Win.Flags & WIN_2BUTTON))
		{
			WinLabel(&p->Win,&y,-1,-1,LangStr(SETTINGS_ID,SETTINGS_HINT),PROPSIZE,0,NULL);
			y += 10;
		}

		for (No=0;NodeEnum(Node,No,&DataDef)==ERR_NONE;++No)
			if ((DataDef.Flags & DF_SETUP) && !(DataDef.Flags & DF_HIDDEN))
			{
				if (DataDef.Flags & DF_GAP)
					y += 7;

				if (!(DataDef.Flags & DF_RDONLY))
					WinPropValue(&p->Win,&y,Node,DataDef.No);
				else
				if (Node->Get(Node,DataDef.No,Data,DataDef.Size)==ERR_NONE)
				{
					switch (DataDef.Type)
					{
					case TYPE_LABEL:
						WinLabel(&p->Win,&y,-1,-1,DataDef.Name,PROPSIZE,0,NULL);
						break;

					case TYPE_TICK:
						TickToString(Data,TSIZEOF(Data),*(tick_t*)Data,0,1,0);
						WinPropLabel(&p->Win,&y,DataDef.Name,Data);
						break;

					case TYPE_INT:
						i = *(int*)Data;

						if (DataDef.Flags & DF_ENUMCLASS)
							tcscpy_s(Data,TSIZEOF(Data),LangStr(i,NODE_NAME));
						else
						if (DataDef.Flags & DF_ENUMSTRING)
							tcscpy_s(Data,TSIZEOF(Data),LangStr(DataDef.Format1,i));
						else
							Data[0] = 0;

						if (!Data[0])
							IntToString(Data,TSIZEOF(Data),i,(DataDef.Flags & DF_HEX)!=0);
						if (DataDef.Flags & DF_KBYTE)
							tcscat_s(Data,TSIZEOF(Data),T(" KB"));
						if (DataDef.Flags & DF_MHZ)
							tcscat_s(Data,TSIZEOF(Data),T(" Mhz"));
						WinPropLabel(&p->Win,&y,DataDef.Name,Data);
						break;

					case TYPE_STRING:
						WinPropLabel(&p->Win,&y,DataDef.Name,Data);
						break;
						
					case TYPE_HOTKEY:
						HotKeyToString(Data,TSIZEOF(Data),*(int*)Data);
						WinPropLabel(&p->Win,&y,DataDef.Name,Data);
						break;
						
					case TYPE_BOOL:
						WinPropLabel(&p->Win,&y,DataDef.Name,
							LangStr(PLATFORM_ID,*(bool_t*)Data ? PLATFORM_YES:PLATFORM_NO));
						break;

					default:
						WinPropLabel(&p->Win,&y,DataDef.Name,NULL);
						break;
					}
				}
			}
	}

	WinEndUpdate(&p->Win);
}
コード例 #15
0
ファイル: streams.c プロジェクト: robUx4/ResInfo
void StreamClose(stream* File)
{
	NodeDelete((node*)File);
}
コード例 #16
0
ファイル: card_game1.c プロジェクト: csvwolf/Sky-C-Study
int main(void)
{
    /* 不同花色分组 */
    // int card[4][13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
    /* 不分花色版 */
    int cards[13] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
    int total = CARDTOTAL;
    int num, position, i, turn = 1;
    Node *p;
    LinkList cardDeck1 = InitList();
    LinkList cardDeck2 = InitList();
    srand((unsigned int)time(NULL));
    printf("扑克牌配对开始,输入1-13的数字抓牌吧。\n");

    while (total > 0)
    {

        if (turn)
        {
            //printf("换行即抽牌");
            //while (getchar() != '\n');
            printf("玩家正在抽牌");
            for (i = 0; i < 3; i++)
            {
                _sleep(rand() % 10 * 100);
                putchar('.');
            }
            while(num = 1+(int)(13.0*rand()/(RAND_MAX+1.0)), cards[num - 1] <= 0);
            printf("抽到牌:%d", num);
            putchar('\n');
            position = GetElem(cardDeck1, num);
            p = NodeShow(cardDeck1, position);
            if (p && p->data == num)
            {
                NodeDelete(cardDeck1, position);
            }
            else
            {
                NodeInsert(cardDeck1, position, num);
            }
            total--;
            cards[num - 1]--;
            printf("玩家手中牌(NULL表示无):");
            if (ElemCount(cardDeck1))
            {
                Traverse(cardDeck1, Show);
            }
            else
            {
                printf("NULL");
            }
        }
        else
        {
            printf("系统正在抽牌");
            for (i = 0; i < 3; i++)
            {
                _sleep(rand() % 10 * 100);
                putchar('.');
            }
            while(num = 1+(int)(13.0*rand()/(RAND_MAX+1.0)), cards[num - 1] <= 0);
            printf("抽到牌:%d", num);
            putchar('\n');
            position = GetElem(cardDeck2, num);
            p = NodeShow(cardDeck2, position);
            if (p && p->data == num)
            {
                NodeDelete(cardDeck2, position);
            }
            else
            {
                NodeInsert(cardDeck2, position, num);
            }
            total--;
            cards[num - 1]--;
            printf("系统手中牌(NULL表示无):");
            if (ElemCount(cardDeck2))
            {
                Traverse(cardDeck2, Show);
            }
            else
            {
                printf("NULL");
            }
        }
        putchar('\n');
        turn = !turn;
    }
    printf("本轮结束,牌全部用完,谢谢拉\n");
    getchar();
    return 0;
}