Exemple #1
0
int CStrings::Split(LPCTSTR Line, TCHAR Delim)
{
	RemoveNodes();

	CStringNode *last = first_node;
	CString tmp = Line;
	int pos = tmp.Find( Delim );
	while ( pos >= 0 )
	{
		CString val = tmp.Left(pos);
		val.TrimLeft();
		val.TrimRight();

		tmp = tmp.Mid( pos+1 );
		pos = tmp.Find( Delim );

		Append( val );
	}

	if ( ! tmp.IsEmpty() )
	{
		tmp.TrimLeft();
		tmp.TrimRight();
		Append( tmp );
	}

	return num;
}
/*
int IsLeafNode(struct TNode* root){
return root->left==NULL && root->right==NULL;
}


int GetSum(struct TNode** buffer,int index){
int i;
int sum=0;
for(i=0;i<index;i++){
sum+=buffer[i]->data;
}
printf("\n198 Sum: %d",sum);
return sum;
}

void RunDeletionProcess(struct TNode** buffer,int index){
int i;
struct TNode* tmpNode;
for(i=index-1;i>=0;i--){
if(IsLeafNode(buffer[i])){
free(buffer[i]);
buffer[i]=NULL;
}else{
break;
}
}
}

void RemoveBekarNodes(struct TNode** root,struct TNode** buffer,int K,int index){
if(!(*root)){
return;
}
printf("\n216\n");
buffer[index++]=(*root);

if(!(*root)->left && !(*root)->right){
int sum=GetSum(buffer,index);
 printf("\nEntering here: sum:%d\n",sum);
if(sum<K){

RunDeletionProcess(buffer,index);
return;
}
}
if((*root)->left){
RemoveBekarNodes(&(*root)->left,buffer,K,index);
}
if((*root)->right){
RemoveBekarNodes(&(*root)->right,buffer,K,index);
}
}
*/
struct TNode* RemoveNodes(struct TNode* root,int K,int* sum){
if(root==NULL){
return NULL;
}

int lSum=*sum+root->data;
int rSum=lSum;


root->left=RemoveNodes(root->left,K,&lSum);
root->right=RemoveNodes(root->right,K,&rSum);
(*sum)=max(lSum,rSum);
if(*sum<K){
    (*sum)-=root->data;
free(root);
root=NULL;
}
return root;

}
Exemple #3
0
void CChildView::ResizeNode(CNodeClass* pClass, UINT idx, DWORD before, DWORD After)
{
	if (!pClass || idx == MAX_NODES)
		return;

	if (before != After)
	{
		if (After < before)
			FillNodes(pClass, idx + 1, before - After);
		else
			RemoveNodes(pClass, idx + 1, After - before);
	}

	theApp.CalcAllOffsets();
}
Exemple #4
0
void
inDOMView::CollapseNode(PRInt32 aRow)
{
  inDOMViewNode* node = nsnull;
  nsresult rv = RowToNode(aRow, &node);
  if (NS_FAILED(rv)) {
    return;
  }

  PRInt32 row = 0;
  GetLastDescendantOf(node, aRow, &row);

  RemoveNodes(aRow+1, row-aRow);

  node->isOpen = PR_FALSE;
}
int main(){

struct TNode* root=NULL;
printf("\nEnter the number of elements you want to insert : ");
int n;
scanf("%d",&n);

int i,data;
for(i=0;i<n;i++){
printf("\nEnter data : ");
scanf("%d",&data);
InsertBinaryTree(&root,data,n);
}

printf("\nInserted... %d nodes \n",n);

getch();

printf("\nPress enter to do level-order traversal : \n\n");
getch();
LevelOrderTraversal(root,n);
getch();
printf("\nEnter the value of K : ");
int K;
scanf("%d",&K);
printf("\nPress enter to remove unwanted nodes\n\n");
getch();
/*
struct TNode** buffer=(struct TNode**)malloc(sizeof(struct TNode*)*n);
for(i=0;i<n;i++){
buffer[i]=(struct TNode*)malloc(sizeof(struct TNode));
}

RemoveBekarNodes(&root,buffer,K,0);
*/
int sum=0;
root=RemoveNodes(root,K,&sum);

printf("\nPress enter to traverse modified tree\n\n");
getch();
LevelOrderTraversal(root,n);
return 0;
}
Exemple #6
0
void CChildView::ReplaceNode(CNodeClass* pClass, UINT idx, CNodeBase* pNewNode)
{
	if (!pClass || idx == MAX_NODES)
		return;

	CNodeBase* pOldNode = pClass->Nodes[idx];
	pNewNode->Name = pOldNode->Name;
	pNewNode->Comment = pOldNode->Comment;

	// This looks wrong
	//if ( pOldNode->offset < 0x140000000 )
	//{
	//	pNewNode->offset = 0x140000000;
	//	pNewNode->strOffset = "0x140000000";
	//} else {
	//	pNewNode->offset = pOldNode->offset;
	//}

	pNewNode->pParent = pClass;
	pNewNode->bSelected = false;

	//m_pSelected = pNewNode;
	pClass->Nodes[idx] = pNewNode;

	DWORD sOld = pOldNode->GetMemorySize();
	DWORD sNew = pNewNode->GetMemorySize();

	if (sOld != sNew)
	{
		if (sNew < sOld)
			FillNodes(pClass, idx + 1, sOld - sNew);
		else
			RemoveNodes(pClass, idx + 1, sNew - sOld);
	}

	delete pOldNode;

	theApp.CalcAllOffsets();
}
	void XMLNode::Clear()
	{
		RemoveFields();
		RemoveNodes();
	}