Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 23rd, 2004, 05:39 AM
uNdErTaKeR uNdErTaKeR is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Athens, Greece
Posts: 1 uNdErTaKeR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to uNdErTaKeR
B+ Tree help ! ! !

Hi to all of you!!!

I am new to Java programming, as I am a student and new to this forum!!!

I have a problem in a assignment for my university.
I must build a B+ Tree which stores keys from records...
The Code tha I have build until now is this one :
Class Tree
Code:
import java.util.*;
public class Tree {
    
    private int p;
    private int pLeaf;
    private float fillFactor;
    Node root;
    public Tree(int p, int pLeaf, float fillFactor) {
        this.p = p;
        this.pLeaf = pLeaf;
        this.fillFactor = fillFactor;
        this.root = new NodeLeaf(pLeaf);        
    }
    
    public void insert(int key){
        Node n;
        Stack parents = new Stack();
        int numberOfPointers;
        n = this.root;
        while ( !(n instanceof NodeLeaf) ){
            parents.push(n);
            numberOfPointers = this.p;
            if (key <= n.printKey(0)) {
                n = n.children[0];
            }
            else if ( key > n.printKey(numberOfPointers - 1) && n.printKey(numberOfPointers - 1) != 0 ){
                n = n.children[numberOfPointers];
            }
            else{
                int position;
                // It searches the Node for the position where the key must be placed.
                position = n.search(key);
                n = n.printChildren(position);
            }
        }
        
        // It searches the NodeLeaf if the key already exists in the database.
        int found;
        found = n.search(key);
        if (found == 1){
            System.out.println (" The record is already in the databse. It cannot be inserted again!");
        }
        else{
            if ( !(n.isTheNodeFull()) ){
                n.insert(key);
            }
            else{
                NodeLeaf temp = new NodeLeaf(pLeaf + 1);
                temp = n;
                temp.insert(key);
                NodeLeaf newLeaf = new NodeLeaf(pLeaf); 
                newLeaf.pNext = n.pNext;
            }
        }
    }

    
    public void delete(){
    }
    
    public void update(){
    }
    
    public void search(){
    }
    
}


Class Node:
Code:
public class Node {
    private int p;
    private int []key;
    NodeLeaf []children;
    
    public Node() {
    }
    
    
    public Node(int p) {
        this.p = p;
        this.key = new int[p-1];
        this.children = new NodeLeaf[p];
    }
    
    public void insert(int key){
    }
    
    public void delete(){
    }
    
    public void update(){
    }
    
    /* The function search, searches between witch keys fits the gives search key. */
    /* When the position i in the arreay is found, it is returned.                 */
    public int search(int key){
        int i;
        for(i=1; i<this.key.length-1; i++){
            if (  ( this.key[i-1]< key ) && ( key <= this.key[i] )  ){
                break;
            }
        }
        return i;
    }
    
    public boolean isTheNodeFull(){
        for (int i=0; i<this.key.length; i++) {
            if ( this.key[i] == 0 ){
                return false;
            }
        }
        return true;
    }
        
    
    public Node printChildren(int i){
        return this.children[i];
    }
    
    public int printKey(int i){
        return this.key[i];
    }
    
    public void changeChildren(int i, NodeLeaf newChildren){
        this.children[i] = newChildren;
    }
    
    public void changeKey(int i, int newKey){
        this.key[i] = newKey;
    }
    
}


Class NodeLeaf:
Code:
public class NodeLeaf extends Node{
    private int pLeaf;
    int []key;
    NodeLeaf pNext;
    
    public NodeLeaf() {
    }
    
    
    public NodeLeaf(int pLeaf) {
        this.pLeaf = pLeaf;
        this.key = new int[pLeaf];
    }
    
    public void insert(int key){
        for(int i=0; i<this.key.length; i++){
            if (this.key[i] == 0){
                this.key[i] = key;
            }
        }
    }
    
    public void delete(){
    }
    
    public void update(){
    }
    
    
    /* The search function search for the key in the NodeLeaf.        */
    /* If found, it means that the key already exists in the database */
    /* so it prints the apropriate message and returns 0. If not found*/
    /* thesn returns 1.                                               */
    public int search(int key){
        int i;
        for (i=0; i<this.key.length; i++) {
            if ( this.key[i] == key ){
                System.out.println("The record is in tha database");
                return 1;
            }
        }
        return 0;
    }
    
    public boolean isTheNodeFull(){
        for (int i=0; i<this.key.length; i++) {
            if ( this.key[i] == 0 ){
                return false;
            }
        }
        return true;
    }
    
    
}


So here is my problem now (the red one):
the insert in class Tree. The compiler throws this message :

Code:
Tree.java [49:1] incompatible types
found   : Node
required: NodeLeaf
                temp = n;
                       ^
Tree.java [52:1] cannot resolve symbol
symbol  : variable pNext 
location: class Node
                newLeaf.pNext = n.pNext;
                                 ^
2 errors
Errors compiling Tree.


And I don't know how to solve it !!!
Please if anyone can help me )

Reply With Quote
  #2  
Old January 23rd, 2004, 07:13 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 10
As for line 49....

How can a NodeLeaf = a new Node?
Sounds like a type mismatch... what is it you're trying to do here?

The second error is linked to the first... fix the first and the second will go away =)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > B+ Tree help ! ! !


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek