
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


 
// define a class to contain the two fields
// accessors to get/set the field values are automatically generated
class Point
{
  Int x
  Int y
}
 
class Main
{
  public static Void main ()
  {
    // empty constructor, so x,y set to 0
    point1 := Point()
    // constructor uses with-block, to initialise values
    point2 := Point { x = 1; y = 2}
    echo ("Point 1 = (" + point1.x + ", " + point1.y + ")")
    echo ("Point 2 = (" + point2.x + ", " + point2.y + ")")
  }
}
 