Example #1
0
File: AVL.c Project: GitMMM/C_Study
void _delete(TreeNode *tree_node, int num, int lorr)
{
	if (num > tree_node->num) {
		if (tree_node->right) {
			_delete(tree_node->right, num, RIGHT_NODE);
		} else {
		}
	} else if (num < tree_node->num) {
		if (tree_node->left) {
			_delete(tree_node->left, num, LEFT_NODE);
		}
	} else {
		TreeNode *p_node;
		p_node	= tree_node->parent;
		
		int l_height, r_height;
		l_height	= tree_node->left ? tree_node->left->height : -1;
		r_height	= tree_node->right ? tree_node->right->height : -1;
		if (l_height > r_height) {

		} else if (l_height < r_height) {

		} else {
		}
	}
}
Example #2
0
int main(void)
{
    tree start = *new_tree(int_compare).value;
    print_tree(start);
    start = insert(start, FatPointer<int>(1)).out;
    print_tree(start);
    start = insert(start, FatPointer<int>(3)).out;
    print_tree(start);
    start = insert(start, FatPointer<int>(5)).out;
    print_tree(start);
    start = insert(start, FatPointer<int>(7)).out;
    print_tree(start);
    start = insert(start, FatPointer<int>(0)).out;
    print_tree(start);
    start = insert(start, FatPointer<int>(4)).out;
    print_tree(start);
    insert(start, FatPointer<int>(2));
    print_tree(start);
    start = find(start, FatPointer<int>(7)).out;
    print_tree(start);
    start = find(start, FatPointer<int>(2)).out;
    print_tree(start);
    start = _delete(start, FatPointer<int>(5)).out;
    print_tree(start);
    start = _delete(start, FatPointer<int>(2)).out;
    print_tree(start);
}
AdvancedSettingsWnd::AdvancedSettingsWnd(QWidget *parent)
    : QWidget(parent)
{
	ui.setupUi(this);
#ifdef Q_WS_MAEMO_5
	setWindowFlags(windowFlags() | Qt::Window);
//	setAttribute(Qt::WA_Maemo5StackedWindow, true);
	// workaround for stacked window not working correclty:
	setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
	setWindowModality(Qt::WindowModal);
#else
    setParent(NULL);
#endif
	if (true) // TODO zzzz; auto-detect orientation
	{
		// switch to portrait mode
		QHBoxLayout* buttonBoxLayout = new QHBoxLayout();
		ui.buttonBoxSpacer->changeSize(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
		ui.buttonBoxLayout->removeItem(ui.buttonBoxSpacer);
		_delete(ui.buttonBoxSpacer);
		ui.verticalLayout->removeWidget(ui.buttonBox);
		buttonBoxLayout->addWidget(ui.buttonBox);

		ui.gridLayout->removeItem(ui.buttonBoxLayout);
		_delete(ui.buttonBoxLayout);
		ui.gridLayout->addItem(buttonBoxLayout, 1, 0, 1, 1);
	}
    m_result = QDialog::Rejected;
}
Example #4
0
	// const to allow shared_ptr<T const>
	void release() const
	{
#if GVL_THREADSAFE
		#error "Not finished"
		if(_ref_count == 1) // 1 means it has to become 0, nobody can increment it after this read
			_delete();
		else
		{
			// TODO: Implement CAS
			int read_ref_count;
			do
			{
				read_ref_count = _ref_count;
			}
			while(!cas(&_ref_count, read_ref_count, read_ref_count - 1));
			
			if(read_ref_count - 1 == 0)
			{
				_clear_weak_ptrs();
				_delete();
			}
		}
#else
		--_ref_count;
		if(_ref_count == 0)
		{
			_clear_weak_ptrs();
			_delete();
		}
#endif
	}
Example #5
0
void config_destroy(config_t *config)
{
  unsigned int count = config->num_filenames;
  const char **f;

  __config_setting_destroy(config->root);

  for(f = config->filenames; count > 0; ++f, --count)
    _delete(*f);
  _delete(config->filenames);

  memset((void *)config, 0, sizeof(config_t));
}
Example #6
0
int
__p2close(int *fdp, FILE **fpp, int kill_sig)
{
	int		fds[2];
	int		status;
	void		(*hstat)(int), (*istat)(int), (*qstat)(int);
	pid_t pid, r;

	if (fdp != NULL) {
		fds[0] = fdp[0];
		fds[1] = fdp[1];
	} else if (fpp != NULL) {
		fds[0] = fileno(fpp[0]);
		fds[1] = fileno(fpp[1]);
	} else {
		return (-1);
	}

	pid = _delete(fds[0]);
	if (pid != _delete(fds[1]))
		return (-1);

	if (pid == (pid_t)-1)
		return (-1);

	if (kill_sig != 0) {
		(void) kill(pid, kill_sig);
	}

	if (fdp != NULL) {
		(void) close(fds[0]);
		(void) close(fds[1]);
	} else {
		(void) fclose(fpp[0]);
		(void) fclose(fpp[1]);
	}

	istat = signal(SIGINT, SIG_IGN);
	qstat = signal(SIGQUIT, SIG_IGN);
	hstat = signal(SIGHUP, SIG_IGN);
	while ((r = waitpid(pid, &status, 0)) == (pid_t)-1 && errno == EINTR)
		;
	if (r == (pid_t)-1)
		status = -1;
	(void) signal(SIGINT, istat);
	(void) signal(SIGQUIT, qstat);
	(void) signal(SIGHUP, hstat);
	return (status);
}
void vsx_widget_controller_sequence::vsx_command_process_b(vsx_command_s *t) {
  if (t->cmd == "update")
  {
    //printf("command gotten from chan: %s\n",t->raw.c_str());
    command_q_b.add_raw("param_set "+(target_param!= ""?(target_param+" "):"")+t->parts[2]+command_suffix);
    parent->vsx_command_queue_b(this);
  } else
  if (t->cmd == "pg_ok") {
    command_q_b.add_raw("pseq_p_ok inject_get foo bar "+t->parts[3]);
    seq_chan->vsx_command_queue_b(this);
  }
  else
  if (t->cmd == "pg64_ok") {
#ifdef VSXU_DEBUG
    printf("command gotten from server: %s\n",t->raw.c_str());
#endif
    command_q_b.add_raw("pseq_p_ok inject_get foo bar "+base64_decode(t->parts[3]));
    seq_chan->vsx_command_queue_b(this);
  }
  else
	if (t->cmd == "menu_close" || t->cmd == "remove_chan") {
		if (!parent_removal)
		{
			_delete();
		} else
		{
			command_q_b.add_raw("controller_sequence_close "+i2s(id)+command_suffix);
			parent->vsx_command_queue_b(this);
		}
  }
}
Example #8
0
int imei_destory(RBT_IMEI **root)
{
	while(*root != NULL) {
                *root = _delete(*root, (*root)->IMEI);
        }
	return 0;
}
Example #9
0
void
ModelEditor::on__model_editor_tab_tabCloseRequested (int index)
{
  if (index < 0)
    return;
  ModelInfo mi = _models->value (index);
  if (!mi.init ())
    {
      if (mi.dirty ())
	{
	  QMessageBox::StandardButton res = QMessageBox::question (
	      this, "Save",
	      QString ("Save changes to file ") + mi.name () + QString ("?"),
	      QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
	  if (res == QMessageBox::Save)
	    {
	      _save (index);
	    }
	  else if (res == QMessageBox::Cancel)
	    {
	      return;
	    }
	}
    }
  else
    {
      mi.setInit (false);
      _models->replace (index, mi);
    }
  _delete (index);
}
Example #10
0
/*	==================== _delete ==================== 
	Deletes node from the tree (key must be unique!)
	   Pre    tree initialized--null tree is OK.
	          dataPtr contains key of node to be deleted
	   Post   node is deleted and its space recycled
	          -or- if key not found, tree is unchanged 
	   Return success is true if deleted; false if not found
	          pointer to root
*/
static BSTNODE* _delete (HEADER* listHeader, BSTNODE* root,  char* dataPtr, int* success)
{
	BSTNODE* dltPtr;
	BSTNODE* exchPtr;
	BSTNODE* newRoot;
	PACKAGE* holdPtr;

	if (!root){
	    *success = 0;
	    return NULL;
	}
	
	if (strcmp(dataPtr, root->ptrPackage->name) < 0)
	    root->left  = _delete (listHeader, root->left, dataPtr, success);
	else if (strcmp(dataPtr, root->ptrPackage->name) > 0)
	    root->right = _delete (listHeader, root->right, dataPtr, success);
	else{ // Delete node found--test for leaf node 
	    dltPtr = root;
		if (!root->left){         // No left subtree 
            //free (root->dataPtr);       // data memory
	        newRoot = root->right;
	        free (dltPtr);              // BST Node
	        *success = 1;
	        return newRoot;             // base case 
	     }
	     else
			 if (!root->right){   // Only left subtree 
	             newRoot = root->left;
	             free (dltPtr);
	             *success = 1;
	             return newRoot;         // base case 
	         }
			 else{ // Delete Node has two subtrees 
                 exchPtr = root->left;
	             // Find largest node on left subtree
	             while (exchPtr->right)
	                 exchPtr = exchPtr->right;

	              // Exchange Data 
	              holdPtr          = root->ptrPackage;
	              root->ptrPackage    = exchPtr->ptrPackage;
	              exchPtr->ptrPackage = holdPtr;
				  root->left = _delete (listHeader, root->left, exchPtr->ptrPackage->name, success);
			 }// else 
	}// node found 
	return root; 
}// _delete 
Example #11
0
	void _cleanup(void)
	{
		if(_data)
		{
			assert(_delete);
			_delete(_data);
		}
	}
Example #12
0
Handle<CLType, CUType>::~Handle()
{
  if(backend_==CUDA && has_ownership_ && cu_ && cu_.unique() && *cu_){
    _delete(*cu_);
  }
  if(backend_==OPENCL && has_ownership_ && cl_ && cl_.unique() && *cl_)
     release(*cl_);
}
Example #13
0
static void __config_list_destroy(config_list_t *list)
{
  config_setting_t **p;
  unsigned int i;

  if(! list)
    return;

  if(list->elements)
  {
    for(p = list->elements, i = 0; i < list->length; p++, i++)
      __config_setting_destroy(*p);

    _delete(list->elements);
  }

  _delete(list);
}
Example #14
0
void explosion_reset_all ()
{
   u16 i;

   for ( i=0; i<EXPLOSION_TERRAIN_MAX; i++ )
   {
      _delete ( i );
   }
}
int _test(CIMClient& client, const char* opt, String& qlang)
{
  if (String::equalNoCase (opt, "setup"))
  {
    _setup (client, qlang);
  }
  else if (String::equalNoCase (opt, "setup2"))
  {
    _setup2 (client, qlang);
  }
  else if (String::equalNoCase (opt, "create"))
  {
    _create (client);
  }
  else if (String::equalNoCase (opt, "create2"))
  {
    _create2 (client);
  }
  else if (String::equalNoCase (opt, "sendSucceed"))
  {
    _sendSucceed (client);
  }
  else if (String::equalNoCase (opt, "sendFail"))
  {
    _sendFail (client);
  }
  else if (String::equalNoCase (opt, "sendBlock"))
  {
    _sendBlock (client);
  }
  else if (String::equalNoCase (opt, "delete"))
  {
    _delete (client);
  }
  else if (String::equalNoCase (opt, "delete2"))
  {
    _delete2 (client);
  }
  else if (String::equalNoCase (opt, "cleanup"))
  {
    _cleanup (client);
  }
  else if (String::equalNoCase (opt, "cleanup2"))
  {
    _cleanup2 (client);
  }
  else
  {
    PEGASUS_STD (cerr) << "Invalid option: " << opt 
                       << PEGASUS_STD (endl);
    _usage ();
    return -1;
  }
  
  return 0;
}
Example #16
0
bool removeNode(LIST* pList, void* keyPtr) {
    bool found;
    LIST_NODE *pPre, *pLoc;

    found = _search(pList, &pPre, &pLoc, keyPtr);
    if (found)
        _delete(pList, pPre, pLoc);

    return found;
}
Example #17
0
bool removeNode (LIST* pList, void* keyPtr, void** dataOutPtr)
{
	bool found;
	NODE* pPre;
	NODE* pLoc;

	found = _search (pList, &pPre, &pLoc, keyPtr);
	if (found) _delete (pList, pPre, pLoc, dataOutPtr);

	return found;
}
Example #18
0
void _delete(SBT *x, ll key){  
    SBT t = NULL;  
    if (*x == NULL) return;  
    (*x)->size--;  
    if ((*x)->key == key){  
        if ((*x)->cnt > 1){  
            (*x)->cnt--;  
        } else {  
            if (!(*x)->ch[0] || !(*x)->ch[1]){  
                *x = (*x)->ch[0] ? (*x)->ch[0] : (*x)->ch[1];  
            } else {  
                t = (*x)->ch[1];  
                for (; t->ch[0] != NULL; t = t->ch[0]);  
                _delete(&((*x)->ch[1]), (*x)->key = t->key);  
            }  
        }  
    } else {  
        _delete(&((*x)->ch[key > (*x)->key]), key);  
    }  
}  
Example #19
0
void
_test (CIMClient & client)
{
  try
  {
    String wql ("WQL");
    String cql ("CIM:CQL");

    char cnt[512];
    String filter;
    String query;
    String handler;
    for (Uint32 i = 0; i < QUERIES; i++)
      {

	filter.clear ();
	sprintf (cnt, "%d", i);

	filter.append (_filter);
	filter.append (cnt);

	handler.clear ();
	handler.append (_handler);
	handler.append (cnt);

	query.clear ();
	query.append (queries[i]);

	if (verbose)
	  {
	    cerr << " Creating filter " << filter << endl;
	    cerr << " with query: " << query << endl;
	    cerr << " and handler" << handler << endl;
	  }
	_addFilter (client, filter, query, cql);

	_addHandler (client, handler, _destination);

	_addSubscription (client, filter, handler);

	_delete (client, filter, handler);
      }
  }

  catch (Exception & e)
  {
    cerr << "test failed: " << e.getMessage () << endl;
    exit (-1);
  }

  cout << "+++++ test completed successfully" << endl;
}
Example #20
0
void ByteArray::load ( const char* buf,int len )
{
	_delete();
	if ( len>0 )
	{
		size=len;
		data=new char[size+1];
		if ( !data )
			throw string ( "Not enouth memory" );
		memcpy ( data,buf,len );
		data[size]=0;
	}
}
Example #21
0
static void __config_setting_destroy (config_setting_t * setting)
{
    if (setting)
    {
        if (setting->name)
            _delete (setting->name);

        if (setting->type == CONFIG_TYPE_STRING)
            _delete (setting->value.sval);

        else if ((setting->type == CONFIG_TYPE_GROUP) || (setting->type == CONFIG_TYPE_ARRAY) || (setting->type == CONFIG_TYPE_LIST))
        {
            if (setting->value.list)
                __config_list_destroy (setting->value.list);
        }

        if (setting->hook && setting->config->destructor)
            setting->config->destructor (setting->hook);

        _delete (setting);
    }
}
Example #22
0
int config_setting_set_string(config_setting_t *setting, const char *value)
{
  if(setting->type == CONFIG_TYPE_NONE)
    setting->type = CONFIG_TYPE_STRING;
  else if(setting->type != CONFIG_TYPE_STRING)
    return(CONFIG_FALSE);

  if(setting->value.sval)
    _delete(setting->value.sval);

  setting->value.sval = (value == NULL) ? NULL : strdup(value);
  return(CONFIG_TRUE);
}
 void wrkng(int choice)
 {
 switch(choice)
 {
 case 1: add();   break;
 case 2: _delete();   break;
 case 3: modify();   break;
 case 4: search();   break;
 case 5: about();   break;
 case 6: exitg();   break;
 default: exit(0);   break;
 }
 }
Example #24
0
/* ================== BST_Delete ================== 
	This function deletes a node from the tree and 
	rebalances it if necessary. 
	   Pre    tree initialized--null tree is OK
	          dltKey is pointer to data structure 
	                 containing key to be deleted 
	   Post   node deleted and its space recycled 
	          -or- An error code is returned 
	   Return Success (true) or Not found (false)
*/
int BST_Delete (HEADER* listHeader, char* dltKey)
{
	int  success;
	BSTNODE* newRoot;
	
	newRoot = _delete (listHeader, listHeader->treeRoot, dltKey, &success);
	if (success){
		listHeader->treeRoot = newRoot;
	    (listHeader->count)--;
	    if (listHeader->count == 0) // Tree now empty 
			listHeader->treeRoot = NULL;
	} 
	return success;
}// BST_Delete
Example #25
0
int client::rm()
{
    if(m_cmd.size() < 2)
    {
        cout << "missing oprand." << endl;
        return 0;
    }

    char file_dir[BUFFSIZE] = {0};
    strcpy(file_dir, m_cmd[1]);

    if( m_guider.is_at_local() )
    {
        return _delete(file_dir);
    }
    else
    {
        m_buff.clear();

        // Add the pack type.
        m_buff.push_front(PT_RM);

        // Add the oprand.
        add_buff(file_dir, strlen(file_dir) );

        // Add the checkcode.
        m_analyser.load_data(m_buff);
        m_buff.push_back(m_analyser.check());

        if( -1 == send_data() )
        {
            return -1;// Send error.
        }

        char pack_type = acceptable();
        if( is_pack_type(PT_NOENT, pack_type) )
        {
            cout << "file or directory is not exist"
                << endl;
        }
        else if( is_pack_type(PT_DOERR, pack_type) )
        {
            cout << "remove file or directory error"
                << endl;
        }
    }

    return 0;
}
Example #26
0
void vsx_widget_note::command_process_back_queue(vsx_command_s *t) {
  if (t->cmd == "close") {
    command_q_b.add_raw("note_delete "+name);
    parent->vsx_command_queue_b(this);
    _delete();
  } else
  if (t->cmd == "save") {
    save();
  } else
  if (t->cmd == "pg64_ok") {
    // pg64_ok [comp] [param] [val] [id]
    load_text( vsx_string_helper::base64_decode(t->parts[3]));
    a_focus = this;
    k_focus = this;
  }
}
Example #27
0
void explosion_terrain_update ( )
{
   u16 i;

   for ( i=0; i<EXPLOSION_TERRAIN_MAX; i++ )
   {
      if ( expTerrains[i].timeout > 0 )
      {
         --expTerrains[i].timeout;

         if ( expTerrains[i].timeout == 0 )
         {
            _delete ( i );
         }
      }

   }
}
Example #28
0
File: csim.c Project: R7R8/15213
/*Add a new line in the set*/
void _append(int tag, Set *set){
	numMiss++;
	Line *newLine = (Line*)malloc(sizeof(Line));
	if(newLine == NULL){
		exit(1);
	}

	newLine -> tag = tag;
	newLine -> valid = 0;
	newLine -> nextLine = set -> lineHead;
	set -> lineHead = newLine;
	
	if(set -> curLines == set -> maxLines){
		_delete(set);
	}else{
		set -> curLines++;
	}
}
Example #29
0
Status BTreeFile::fullDelete (const void *key, const RID rid)
{
	Keytype oldChildKey;
	void *oldChildKeyPtr = &oldChildKey;


#ifdef BT_TRACE
	cerr << "DELETE " << rid.pageNo << " " << rid.slotNo << " " << (char*)key << endl;
	cerr << "DO" << endl;
	cerr << "SEARCH" << endl;
#endif

	Status st = _delete(key, rid, oldChildKeyPtr, headerPage->root, -1);

#ifdef BT_TRACE
	cerr << "DONE\n";
#endif
	return st;
}
void DMDownloadInfoManager::_saved(const DMDownloadInfo& model)
{
    _delete(model.bookID);
    
    int ok  = sqlite3_bind_text(_sqlite_stmt_insert, 1,       model.bookID.c_str(), -1, SQLITE_TRANSIENT);
        ok |= sqlite3_bind_text(_sqlite_stmt_insert, 2,    model.bookTitle.c_str(), -1, SQLITE_TRANSIENT);
        ok |= sqlite3_bind_text(_sqlite_stmt_insert, 3,     model.imageUrl.c_str(), -1, SQLITE_TRANSIENT);
        ok |= sqlite3_bind_text(_sqlite_stmt_insert, 4, model.alreadyCache.c_str(), -1, SQLITE_TRANSIENT);
        ok |= sqlite3_bind_text(_sqlite_stmt_insert, 5,     model.notCache.c_str(), -1, SQLITE_TRANSIENT);
        ok |= sqlite3_bind_text(_sqlite_stmt_insert, 6,  model.sizeExplain.c_str(), -1, SQLITE_TRANSIENT);
    
	ok |= sqlite3_step(_sqlite_stmt_insert);

	ok |= sqlite3_reset(_sqlite_stmt_insert);

	if( ok != SQLITE_OK && ok != SQLITE_DONE)
		printf("Error in DMDownloadInfoManager._saved()\n");
    else
        CCLog("SAVED DOWNLOADINFO OK");
}