SunQuest
 
           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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #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 4 m 48 sec
Reputation Power: 8
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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway