Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Beginning Java
Making a quadtree from a Matrix using recursion
Anshul Singhal
Greenhorn
Posts: 18
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello guys,
I making a quadtree from a matrix. Please find attached with this post a sample image of how it is done. I ve used recursion but not able to get to the final result.
public quadtree make_quadtree(int a, int b, int c, int d) { //a,b are starting indexes of the matix and c,d are the ending ones. //link_matrix[m][n] is the actual matrix where the data is stored. It is of the type Link defined in a separate class. quadtree temp1 = new quadtree(); quadtree temp2 = new quadtree(); quadtree temp3 = new quadtree(); quadtree temp4 = new quadtree(); if((c-a)==1) { if((link_matrix[a+1][b].idata) != (link_matrix[a][b].idata)) { make_subtree(a,b); } else { if((link_matrix[a][b+1].idata) != (link_matrix[a+1][b+1].idata)) { make_subtree(a,b); } else { if((link_matrix[a][b].idata) != (link_matrix[a+1][b+1].idata)) { make_subtree(a,b); } else { this.make_one_node(a,b); } } } } else { temp1 = make_quadtree(a,b,c/2,d/2); temp2 = make_quadtree((c/2)+1,b,c,d/2); temp3 = make_quadtree((c/2)+1,(d/2)+1,c,d); temp4 = make_quadtree(a,(d/2)+1,c/2,d); Link newLink = new Link(-1, (temp1.first), (temp2.first), (temp3.first), (temp4.first)); first = newLink; } return this; } public void make_one_node(int a,int b) { Link newlink = new Link(link_matrix[a][b].idata,null,null,null,null); first = newlink; } public void make_subtree(int a,int b) { Link newlink = new Link(-1,link_matrix[a][b],link_matrix[a+1][b],link_matrix[a+1][b+1],link_matrix[a][b+1]); first = newlink; }
fig6.jpg
converting matrix into a quadtree
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
y am i getting null pointer exception here?
traffic simulation
Applet not initialized error
Java - Works, but doesnt work...
Applet Not initialized error
More...