
Data Structure

This illustrates a data structure, a means of storing data within a program.

You may see other such structures in the Data Structures category.


Task

Create a compound data type:

  Point(x,y) 



A compound data type is one that holds multiple independent values.



Related task

   Enumeration


See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


 
class Point {
  @x : Int;
  @y : Int;
 
  New() { 
    @x := 0;
    @y := 0;
  }
 
  New(x : Int, y : Int) { 
    @x := x;
    @y := y;
  }
 
  New(p : Point) { 
    @x := p->GetX();
    @y := p->GetY();
  }
 
  method : public : GetX() ~ Int { 
    return @x; 
  }
 
  method : public : GetY() ~ Int { 
    return @y; 
  }
 
  method : public : SetX(x : Int) ~ Nil { 
    @x := x; 
  }
 
  method : public : SetY(y : Int) ~ Nil { 
    @y := y; 
  }
}
 