Posts

Showing posts from 2008

Non Recursive Function to find the mirror show of binary tree

void MerrorTree::merrorview(node **root) { std::stack stakright ; std::stack stackroot; node *tempnode = NULL; node *temproot = NULL; if((*root)->right (*root)->right) { tempnode = *root; while(tempnode) { if(tempnode->left) { stackroot.push(tempnode); if(tempnode->right) stakright.push(tempnode->right); tempnode = tempnode->left ; } else if(tempnode->right) { stackroot.push(tempnode); stakright.push(tempnode->right); tempnode = tempnode->right ; } else { if(stackroot.size()) { temproot = stackroot.top(); stackroot.pop(); swap(&temproot); } if(stakright.size()) { tempnode = stakright.top(); stakright.pop(); } else break; } } }}

Have Simple c Code to create Binary tree

Now the code written bellow will let u start creating binary treee data structure. Firstly know wht is it exactly before start coding binary tree data structure is arrengement of element in a manner in that first node would be the root of tree, then next coming node would be added as the rule bellow 1 if the next node element is smaller then the root the it would be added as left child of root otherwise right one. and remeber intis data structure each node can have only two childs. after first iterartin we will find the suitable node to add the next and the add(search node-add -node) start coding from here structure of node would be typedef struct TreeNode { int data; //data field struct TreeNode *LeftNode;//left child niode address struct TreeNode *RightNode;//right child niode address }treenode; //Making a global root treenode *root =NULL; now function to create node... treenode *makenode(int data) { treenode * tempnode = (treenode *)malloc(sizeof(treenode)); tempnode->Data = data

Simle c code to create link list

Here i have written the best code to start makin link list so enjoy the code....... struct node{ int Data,struct *NextNodeAddress};//defined structure of node //now we will make a golobal head node struct node *Head = NULL; //now going to create node strct node * makenode(int data) { struct node *TempNode = (struct node *)malloc(sizeof(struct node));//memory created TempNode->Data = data; TempNode->NextNodeAddress = NULL; return TempNode; } //used malloc function to create node and use type cast create node type data //create the list void CreateList(struct ** node Head,struct node *NodeToAdd) { struct node *TempNode =&Head; if(&Head == NULL) { &Head = NodeToAdd; TempNode = NodeToAdd;} else{ TempNode->NextNodeAddress = NodeToAdd; TempNode = NodeTOAdd; } } inside the main functionjst put the following call in loop to create olist dynamicallly' main() { CreateList(&Head,makenode(1)); CreateList(&Head,makenode(2)); CreateList(&Head,makenode(3)); Create