15,905,915 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by mahla.r_1993 (Top 14 by date)
mahla.r_1993
29-Jan-13 15:57pm
View
i know how to use debugger but i can not find my problem :(
help !!!!!!
mahla.r_1993
29-Jan-13 15:07pm
View
yes i dont understand
plz help me :(
mahla.r_1993
29-Jan-13 14:59pm
View
it is my code i dont understand what is wrong in this code ?? i can not get a preorder fot avl tree:(
mahla.r_1993
29-Jan-13 14:58pm
View
#include "stdafx.h"
#include<iostream>
using namespace std ;
struct node
{
int key ;
int h;
node *left;
node *root;
node *right;
};
int h(struct node* x)
{
if (x == NULL)
return 0;
return x->h;
}
int balanceavl(struct node *n)
{
if (n == NULL)
return 0;
return (h(n->left) , h(n->right));
}
node* rightrotate(struct node *root)
{
node *node1;
node1=root->left;
root->left=node1->right;
node1->right=root;
root->h = max(h(root->left), h(root->right));
node1->h = max(h(node1->left), h(node1->right));
return node1;
}
node* leftrotate(struct node *root)
{
node *node1;
node1=root->right;
root->right =node1->left;
node1->left =root;
root->h = max(h(root->left), h(root->right));
node1->h = max(h(node1->left), h(node1->right));
return node1;
}
void inorder(struct node *root)
{
if(root !=NULL)
{
inorder(root->left);
cout<<root->key<<endl;
inorder(root->right);
}
}
void preorder(struct node *root)
{
if(root !=NULL)
{
cout<<root->key<<endl;
preorder(root->right);
preorder(root->left);
}
}
struct node *remove(struct node *root, int key)
{
node* successor(struct node *x);
struct node *remove_node;
if (root == NULL)
{
return root;
}
if ( key < root->key)
{
root->left = remove(root->left, key);
}
else if ( key > root->key)
{
root->right = remove(root->right,key);
}
else {
if ((root->left == NULL) && (root->right != NULL)){
remove_node = root->right;
*root = *remove_node;
free(remove_node); // this is for free-ing the memory
} else if ((root->right == NULL) && (root->left != NULL)){
remove_node = root->left;
*root = *remove_node;
free(remove_node);
} else if ((root->right == NULL) && (root->left == NULL)){
remove_node = root;
root = NULL;
} //else {
// remove_node = successor(root);
// root->key = remove_node->key;
// root->right = remove(root->right, remove_node->key);
// }
}
if (root == NULL) {
return root;
//lr
if (balanceavl(root) == 2){
if (balanceavl(root->left) == -1) {
root->left = leftrotate(root->left);
return rightrotate(root);
//ll
} else if (balanceavl(root->left) == 1) {
return rightrotate(root);
}
}
//rr
if (balanceavl(root) == -2) {
if (balanceavl(root->right) == -1) {
return leftrotate(root);
}
//rl
else if (balanceavl(root->right) == 1) {
root->right = rightrotate(root->right);
return leftrotate(root);
}
}
}
return root;
}
struct node* newNode(int key)
{
struct node* node = (struct node*)
malloc(sizeof(struct node));
node->key = key;
node->left = NULL;
node->right = NULL;
node->h = 1; // new node is initially added at leaf
return(node);
}
struct node* insert(struct node* root, int key)
{
/* 1. Perform the normal BST rotation */
if (root == NULL)
return(newNode(key));
if (key < root->key)
root->left = insert(root->left, key);
else
root->right = insert(root->right, key);
/* 2. Update height of this ancestor node */
root->h= max(h(root->left), h(root->right)) + 1;
/* 3. Get the balance factor of this ancestor node to check whether
this node became unbalanced */
int balance = balanceavl(root);
// If this node becomes unbalanced, then there are 4 cases
if (root == NULL) {
return root;
//lr
if (balanceavl(root) == 2){
if (balanceavl(root->left) == -1) {
root->left = leftrotate(root->left);
return rightrotate(root);
//ll
} else if (balanceavl(root->left) == 1) {
return rightrotate(root);
}
}
//rr
if (balanceavl(root) == -2) {
mahla.r_1993
29-Jan-13 14:53pm
View
it use in avl tree
for example when i get 10 20 30 in avl tree
with right rotate i get 20 10 30
mahla.r_1993
29-Jan-13 14:37pm
View
i write just left and right rotate plz read my code and say me what is wrong in this part ??? i want to write a code for avl tree
mahla.r_1993
29-Jan-13 10:04am
View
i get this error:
error C3861: 'successor': identifier not found
mahla.r_1993
29-Jan-13 9:59am
View
i get this from internet
what is wrong for this ? plz help me!
mahla.r_1993
29-Jan-13 9:46am
View
i get this error:
error C3861: 'successor': identifier not found
mahla.r_1993
29-Jan-13 9:43am
View
tnnnnnnnnnnnnnx :)
mahla.r_1993
27-Jan-13 17:46pm
View
tnx but now , what can i do ?
mahla.r_1993
27-Jan-13 15:24pm
View
i dont understand what i must do:(
mahla.r_1993
27-Jan-13 14:35pm
View
i write return null
and after that i get these error :
error LNK1120: 1 unresolved externals
error LNK2019: unresolved external symbol "void __cdecl freeNodeData(struct avl_nodeData * *)" (?freeNodeData@@YAXPAPAUavl_nodeData@@@Z) referenced in function "struct avl_node * __cdecl deleteNode(struct avl_node * *,struct avl_nodeData *,int (__cdecl*)(void *,void *),void (__cdecl*)(struct avl_nodeData * *))" (?deleteNode@@YAPAUavl_node@@PAPAU1@PAUavl_nodeData@@P6AHPAX2@ZP6AXPAPAU2@@Z@Z)
what is wrong?
mahla.r_1993
27-Jan-13 14:23pm
View
i have an error in ( avlNode* deleteNode )
in this part ,
error C2561: 'deleteNode' : function must return a value
what must i do?
Show More