Cramster.com - Homework Solutions, Lecture Notes, Exams, and Free Online Homework Help
Sign Up Now! Login Customer Support Cramster Blog
McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams
Problem Solved.
    Home    
    Homework Help    
   Answer Board   
    Resources (Beta)    
   
Member's Topic Headline:

Data Structure Project

Know the answer? Have a better solution? Share it.
Get Help Now.
View homework problems
explained for free!
Member Testimonials

Question:

Advertisement:

Answer | Ask New Question | Customize Profile | Leaderboards | 
FAQ

Member's Avatar

Rookie
Karma Points: 0
Respect (0%):
Date Posted: 7/22/2008 11:45:22 PM  Status: Live
Data Structure Project
Course Textbook Chapter Problem
N/A N/A N/A N/A
Question Details:
Can someone guide me?


Project Name: Binary Tree Class (Graphical Implementation)

Difficulty Level: Medium for those students who have worked or want to do work in graphics and understand BST class.

Description: This project requires the implementation of all tree related concepts and write an application that will implement all basic tree related concepts and operations and will show the trees graphically.

Basic Idea: We have studied many basic tree related concepts in our data structure course in this project we want to implement these concepts practically using c++ and any graphics library.

For this project we will use win32 or Turbo or Borland c graphics functions of circles and lines drawing to draw trees so this project is a bit more complex the students who have interest in graphics should take this projects, we will guide them.

Answers:

Member's Avatar

Expert
Karma Points: 1,405
Date Posted: 8/5/2008 12:00:06 AM  Status: Live
Asker's Rating: None Provided    Moderator's Rating: Helpful
Response:
//compiled in turbo c++
// implementing BST in graphics mode, taking the node by random function


#include<stdio.h>

#include<graphics.h>

#include<conio.h>

#include<dos.h>

#include<stdlib.h>

#include<iostream.h>

#define max 10

/*max is the maximum number of nodes in BST*/

int midx; // mid value of getmaxx()

struct node

{

int value;

int prob;

struct node *left,*right;

}*first,*p1,*p2; // NODE OF BST

 

struct node * create_bst(struct node*,int,int);

void print_bst(struct node*,int ,int,int,int col);

void draw_optimaltree(int,int,int,int,int,int);

int comparison[max+2][max+1],root_matrics[max+2][max+1];

int num[max]; //value of bst

int prob[max]; // Probability of corresponding value

void main()

{

int i,gd,gm;

clrscr();

gd=DETECT;

initgraph(&gd,&gm,"");

first=NULL;

randomize();

midx=getmaxx();

char str[10];

int j=0;

for(i=0;i<max;i++)

{

num[i]=random(100);

prob[i]=random(10)+1;

sprintf(str,"%5d",num[i]);

// outtextxy(0,j,str);

j=j+10;

}

int temp;

p1=first;

for(i=0;i<max;i++)

first=create_bst(first,num[i],prob[i]); //binary tree has been drawn

setfillstyle(1,2);

setcolor(14);

print_bst(first,0,getmaxx(),10,1);

setfillstyle(1,2);

setcolor(14);

outtextxy(0,0,"BINARY SEARCH TREE");



getch();

closegraph();

}

struct node *create_bst(struct node *p,int val,int prob)

{

if(p==NULL)

{

p=(struct node *)malloc(sizeof(struct node));

p->value=val;

p->prob=prob;

p->left=NULL;

p->right=NULL;

return p;

}

else

{

if(val<=p->value)

{

p->left=create_bst(p->left,val,prob);

}

else

{

p->right=create_bst(p->right,val,prob);

}

}

return p;

}

void print_bst(struct node *p,int x1,int x2,int yy,int col)

{ //x1 x2 are two x coordinate b/w them node is there

//yy is height of node

// col is color

if(p==NULL)

{

// return 0;

}

else

{

char str[10];

sprintf(str,"%d",p->value,p->prob);

// cout<<"\nFirst node is :"<<p->value;

if(p->left!=NULL)

{

line((x1+x2)/2,yy,(x1+(x1+x2)/2)/2,yy+50);

}

if(p->right!=NULL)

{

line((x1+x2)/2,yy,((x1+x2)/2+x2)/2,yy+50);

}

setfillstyle(1,col);

// fillellipse((x1+x2)/2,yy,10,10);

setcolor(col);

pieslice((x1+x2)/2,yy,0,360,10);

setcolor(14);

if(col==5)

{

outtextxy((x1+x2)/2,yy-4,str);

}

else

{

setcolor(15);

outtextxy((x1+x2)/2-15,yy-4,str);

}

print_bst(p->left,x1,(x1+x2)/2,yy+50,3);

print_bst(p->right,(x1+x2)/2,x2,yy+50,5);

free(p);

}

}




Hope this will help you...need any clarification ?



By reading or posting messages on these forums, you are agreeing to the Answer Board's Terms of Service and Conduct (TSC).


About Cramster | Terms of Use | Privacy Policy | Contact Us | Press Room | Site Map | Support | Anti-Cheating Policy

Cramster.com is not affiliated with any publisher. Book covers, title and author names appear for reference only.
Copyright © 2008 Cramster, Inc.