Thursday, July 30, 2009

Addressing Methods

In creating a data structure, it is important to determine how to access the data items. It is determined by the addressing method used. There are two types of addressing methods in general – computed and link addressing methods.

Java Tutorial Sour Code: Addressing Methods: Computed Addressing Method

Computed addressing method is used to access the elements of a structure in pre-allocated space. It is essentially static, an array for example:

int x[] = new int[10];

A data item can be accessed directly by knowing the index on where it is stored.

Link Addressing Method

This addressing method provides the mechanism for manipulating dynamic structures where the size and shape are not known beforehand or if the size and shape changes at runtime. Central to this method is the concept of a node containing at least two fields: INFO and LINK.

Java Tutorial Sour Code: Addressing Methods

In Java,

class Node{
Object info;
Node link;

Node(){
}

Node(Object o, Node l){
info = o;
link = l;
}
}

No comments:

Post a Comment