Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

[GTCD] c++ PROBLEMS ONLY ft. [BISDAK]

Copy verbatim the code and complete the Implementation of the Binary Tree below, the instructions are written as comments:
For iterative version of the tree traversal, you will need a TreeQueue and TreeStack Objects.
TreeQueue is a Queue where the item enqueued and dequeued are TreeNodes object
TreeStack is a stack where the items pushed and popped are TreeNodes Object



#include<iostream.h>
#include "TreeQueue.cpp"
#include "TreeStack.cpp"

typedef struct TreeNode{
int key;
TreeNode *left;
TreeNode *right;
TreeNode *parent;
TreeNode(int data){
key=data;
left=right=parent=NULL;
}

int isRoot(); // return TRUE if the node is root, otherwise FALSE
int isLeaf(); // return TRUE if the node is leaf, otherwise FALSE
int isAncestor(TreeNode *tree); // return TRUE if the node is an ancestor of tree(parameter)
void preorder(); // display preorder listing(using recursion)
void preorderV2(); // display preorder listing(using iteration or while statement code already given)
void levelorder(); // display levelorder listing
void postorder(); // display postorder listing (using recursion)
void postorderV2(); // display postorder listing(using iteration or while statement code already given)
void inorder(); // display inorder listing(using recursion)
int getCount(); // return the number of descendant nodes at any node
int getLevel(); // return the level number of a node e.g. root is level 1
int getHeight(); // return the height of a node e.g. root with no child height is 0
void setLeft(int data);
void setRight(int data);
};


void TreeNode::setLeft(int data){
}

void TreeNode::setRight(int data){

}

int TreeNode::isRoot(){

}

int TreeNode::isLeaf(){

}

void TreeNode::preorder(){

}

void TreeNode::levelorder(){
TreeQueue *queue = new TreeQueue();
queue->enqueue(this);
while (!queue->empty()){
cout<<queue->front->key <<", ";
if (queue->front->left!=NULL)
queue->enqueue(queue->front->left);
if (queue->front->right)
queue->enqueue(queue->front->right);
queue->dequeue();

}
TreeNode::preorderV2(){
StackTree *stack=new StackTree();
stack->push(this);
while(!stack->empty()){
TreeNode *top = stack->top;
stack->pop();
cout<<top->key ;
if (top->right!=NULL) stack->push(top->right);
if (top->left!=NULL) stack->push(top->left);
}
}
TreeNode::postorderV2(){
TreeStack *s1=new TreeStack();
TreeStack *s2=new TreeStack();
s1->push(this);
while(!s1->empty()){
TreeNode *tmp=s1->top;
s2->push(tmp);
s1->pop();
if (tmp->left!=NULL) s1->push(tmp->left);
if (tmp->right!=NULL) s1->push(tmp->right);
}
while(!s2->empty()){
cout<<s2->top->key;
s2->pop();
}
}
// *********** Sample Main *************//
void main(){
TreeNode *root=new TreeNode(30);
root->setLeft(10); root->setRight(6);
root->left->setLeft(15); root->left->setRight(26);
root->right->setLeft(7); root->right->setRight(4);
root->right->left->setLeft(8); root->right->left->setRight(12);
TreeNode *sample=root->left->right
cout<<"Recursive Implementation: \n";
cout<<"\nPreorder: "; root->preorder();
cout<<"\nInorder: "; root->inorder();
cout<<"\nPostorder: "; root->postorder();
cout<<"\nLevel: "; root->getLevel();
cout<<"\nNo of Nodes: "; root->getCount();
cout<<"\nHeight of Node root: "<< root->getHeight();
cout<<"\n"<<sample->key<<" is Root: "<< sample->isRoot();
cout<<"\n"<<sample->key<<" is leaf: "<< sample->isLeaf();
cout<<"\n"<<root->key<<" is ancestor of "<< sample->key<<" "<<root->isAncestor(sample);
cout<<"\n\nIterative Version of order listing";
cout<<"\nLevel Order: "; root->levelorder();
cout<<"\nPre Order: "; root->preorderV2();
cout<<"\nPost Order: "; root->postorderV2();
}





yan po ang problem namen..pa help..
 
Copy verbatim the code and complete the Implementation of the Binary Tree below, the instructions are written as comments:
For iterative version of the tree traversal, you will need a TreeQueue and TreeStack Objects.
TreeQueue is a Queue where the item enqueued and dequeued are TreeNodes object
TreeStack is a stack where the items pushed and popped are TreeNodes Object



#include<iostream.h>
#include "TreeQueue.cpp"
#include "TreeStack.cpp"

typedef struct TreeNode{
int key;
TreeNode *left;
TreeNode *right;
TreeNode *parent;
TreeNode(int data){
key=data;
left=right=parent=NULL;
}

int isRoot(); // return TRUE if the node is root, otherwise FALSE
int isLeaf(); // return TRUE if the node is leaf, otherwise FALSE
int isAncestor(TreeNode *tree); // return TRUE if the node is an ancestor of tree(parameter)
void preorder(); // display preorder listing(using recursion)
void preorderV2(); // display preorder listing(using iteration or while statement code already given)
void levelorder(); // display levelorder listing
void postorder(); // display postorder listing (using recursion)
void postorderV2(); // display postorder listing(using iteration or while statement code already given)
void inorder(); // display inorder listing(using recursion)
int getCount(); // return the number of descendant nodes at any node
int getLevel(); // return the level number of a node e.g. root is level 1
int getHeight(); // return the height of a node e.g. root with no child height is 0
void setLeft(int data);
void setRight(int data);
};


void TreeNode::setLeft(int data){
}

void TreeNode::setRight(int data){

}

int TreeNode::isRoot(){

}

int TreeNode::isLeaf(){

}

void TreeNode::preorder(){

}

void TreeNode::levelorder(){
TreeQueue *queue = new TreeQueue();
queue->enqueue(this);
while (!queue->empty()){
cout<<queue->front->key <<", ";
if (queue->front->left!=NULL)
queue->enqueue(queue->front->left);
if (queue->front->right)
queue->enqueue(queue->front->right);
queue->dequeue();

}
TreeNode::preorderV2(){
StackTree *stack=new StackTree();
stack->push(this);
while(!stack->empty()){
TreeNode *top = stack->top;
stack->pop();
cout<<top->key ;
if (top->right!=NULL) stack->push(top->right);
if (top->left!=NULL) stack->push(top->left);
}
}
TreeNode::postorderV2(){
TreeStack *s1=new TreeStack();
TreeStack *s2=new TreeStack();
s1->push(this);
while(!s1->empty()){
TreeNode *tmp=s1->top;
s2->push(tmp);
s1->pop();
if (tmp->left!=NULL) s1->push(tmp->left);
if (tmp->right!=NULL) s1->push(tmp->right);
}
while(!s2->empty()){
cout<<s2->top->key;
s2->pop();
}
}
// *********** Sample Main *************//
void main(){
TreeNode *root=new TreeNode(30);
root->setLeft(10); root->setRight(6);
root->left->setLeft(15); root->left->setRight(26);
root->right->setLeft(7); root->right->setRight(4);
root->right->left->setLeft(8); root->right->left->setRight(12);
TreeNode *sample=root->left->right
cout<<"Recursive Implementation: \n";
cout<<"\nPreorder: "; root->preorder();
cout<<"\nInorder: "; root->inorder();
cout<<"\nPostorder: "; root->postorder();
cout<<"\nLevel: "; root->getLevel();
cout<<"\nNo of Nodes: "; root->getCount();
cout<<"\nHeight of Node root: "<< root->getHeight();
cout<<"\n"<<sample->key<<" is Root: "<< sample->isRoot();
cout<<"\n"<<sample->key<<" is leaf: "<< sample->isLeaf();
cout<<"\n"<<root->key<<" is ancestor of "<< sample->key<<" "<<root->isAncestor(sample);
cout<<"\n\nIterative Version of order listing";
cout<<"\nLevel Order: "; root->levelorder();
cout<<"\nPre Order: "; root->preorderV2();
cout<<"\nPost Order: "; root->postorderV2();
}





yan po ang problem namen..pa help..

pa help na
 
help po?
panu po magkaka.ruon ng solid color ung circle sa graphics.h?

example po?
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int poly[12]={350,450,350,410,430,400,350,350,300,430,350,450}
initgraph(&gd, &gm" ");
circle(100,100,50);
getch();
close graph();
}


yan po panu po lagyan ng solid color ang circle sa loob pls help
 
nag tatanong ka pa e gusto mo lng kausap si ate natad.

btw ung if ,else, else if statements ay pra sa option ng system kung ano dpat gwin.which is the "if" is ung klngan gwin pra gwin ng system ung nasa loob ng if statement.at kung hnd nasunod ung if na un,hahanap ung system ng bagong statement na sasatisfy sa pinapagwa mo.at kung walang mapuntahan ung system,doon na papasok si else.it means kung hnd masatisfy ung system sa mga if statements,ang gagawin nya ung else statement.

gets? hahahahha

..tama si nmsis..gusto mo lang makausap..
..paxenxa na ella..chickboy talaga yan gaaraX..

:ranting: :rofl:
 
Last edited:
Patulong, teach me what is array, its use, and sample code.

kindly go to this link and it will explain to you what is array with grapichal representation :clap: click the thumbs up dude
:thumbsup: <<<-- click it
 
Last edited:
help po?
panu po magkaka.ruon ng solid color ung circle sa graphics.h?

example po?
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int poly[12]={350,450,350,410,430,400,350,350,300,430,350,450}
initgraph(&gd, &gm" ");
circle(100,100,50);
getch();
close graph();
}


yan po panu po lagyan ng solid color ang circle sa loob pls help

gagamit ka ng floodfill function.
 
panu po gamitin un?

ganito bro. :)

Code:
#include<graphics.h>
#include<conio.h>
void main()
{
 int gd = DETECT, gm;
 //int poly[12]={350,450,350,410,430,400,350,350,300,430,350,450}
 initgraph(&gd, &gm, "");
 setcolor(RED);
 setfillstyle(SOLID_FILL,RED);
 circle(100,100,50);
 floodfill(101,101,RED);
 getch();
 closegraph();
}
 
ganito bro. :)

Code:
#include<graphics.h>
#include<conio.h>
void main()
{
 int gd = DETECT, gm;
 //int poly[12]={350,450,350,410,430,400,350,350,300,430,350,450}
 initgraph(&gd, &gm, "");
 setcolor(RED);
 setfillstyle(SOLID_FILL,RED);
 circle(100,100,50);
 floodfill(101,101,RED);
 getch();
 closegraph();
}

aa okey po tatry ko po kpag ng.pc aku pwde po ba mg.tanung ulit if meOn pa ?
 
hehe pwede po ba makuha no. mo ???para malaman ko ??kasi po madami akong katanungan about c++ ii?
 
Ako po may problem di ko po alam ung mga nkalagay dun sa
file > new > files
file > new > project

di ko po alam ung mga nkalagay dun
merun ba kau description nun? at mga gamit nung mga un?
 
kuya anung mali dito ???
bkit di nagbabago ??naki turo naman ??
#include<iostream.h>
#include<conio.h>
#include<DOS.H>

main()
{
clrscr();

int r,r1,r2,r3,r4,e,e1,e2,e3,e4,g,g1,g2,g3,g4,g5,x;
char y, ans1,ans2,ans3,ans4,ans5;
textcolor(GREEN);
textbackground(BLACK);

gotoxy(34,14);
cout<<"are you ready sir";
if(x==80)
{
clrscr();
gotoxy(2,7);
for(r=1;r<=8;r++)
{
cout<<"";
delay(50);
}
for(r1=7;r1<=20;r1++)
{
gotoxy(2,r1);
cout<<"";
delay(50);
}
gotoxy(3,13);
for(r2=1;r2<=7;r2++)
{
cout<<"";
delay(50);
}
for(r3=7;r3<14;r3++)
{
gotoxy(10,r3);
cout<<"";
delay(50);
}
for(r4=14;r4<=20;r4++)
{
gotoxy(9,r4);
cout<<"";
delay(50);
}
gotoxy(13,11);
for(e=1;e<=8;e++)
{
cout<<"";
delay(50);
}
for(e1=11;e1<=20;e1++)
{
gotoxy(13,e1);
cout<<"";
delay(50);
}
gotoxy(13,15);
for(e3=1;e3<=6;e3++)
{
cout<<"";
delay(50);
}
gotoxy(13,20);
for(e4=1;e4<=8;e4++)
{
cout<<"";
delay(50);
}
gotoxy(23,11);
for(g=1;g<=8;g++)
{
cout<<"";
delay(50);
}
for(g1=11;g1<=20;g1++)
{
gotoxy(23,g1);
cout<<"";
delay(50);
}
gotoxy(23,20);
for(g2=1;g2<=8;g2++)
{
cout<<"";
delay(50);
}
gotoxy(25,15);
for(g3=2;g3<=7;g3++)
{
cout<<"";
delay(50);
}
for(g4=15;g4<=20;g4++)
{
gotoxy(30,g4);
cout<<"";
delay(50);
}
gotoxy(33,11);
for(g=1;g<=8;g++)
{
cout<<"";
delay(50);
}
for(g1=11;g1<=20;g1++)
{
gotoxy(33,g1);
cout<<"";
delay(50);
}
gotoxy(33,20);
for(g2=1;g2<=8;g2++)
{
cout<<"";
delay(50);
}
gotoxy(35,15);
for(g3=2;g3<=7;g3++)
{
cout<<"";
delay(50);
}
for(g4=15;g4<=20;g4++)
{
gotoxy(40,g4);
cout<<"";
delay(50);
}
if(x==80)
{
clrscr();
gotoxy(34,14);
cout<<"are you ready sir";
}
}
getch();
return 0;
}
 
Back
Top Bottom