1D Array Tutorial

This tutorial will illustrate the use of 1 Dimensional arrays in BRIDGES. BRIDGES supports 1D, 2D and 3D arrays and are subclassed from the Array class, which use a generic attribute to define the type of value it contains. Arrays are collections of Bridges Elements. Refer to the 'Array' and 'Element' classes for more information in the BRIDGES API documentation. Typical operations on arrays are supported, such as getting/setting values into an array

This tutorial consists of 3 parts:

  1. A basic tutorial on how to create a small array of BRIDGES elements and visualize it
  2. How to style the array with visual attributes
  3. Advanced features, such as iterators and range loops that can be used with BRIDGES Arrays.

See also

This tutorial gives an introduction to the usage of arrays. You can find the complete documentation of the features in the Doxygen documentation of the following classes and functions:

  1. Array1D [Java] [C++] [Python]
  2. Element [Java] [C++] [Python]

1. Getting Started: Build a Barebones 1D Array

In the first part of the tutorial, we will create a 1D BRIDGES array of integers, fill it with values, provide BRIDGES a handle to the data structure and visualize the array. Here is the code for this tutorial.

Java
C++
Python

Make sure that you can run the basic tutorial.

If you follow the URL given to you when the application runs, it will get to to the Bridges webpage that shows your output (shown below). You do not need to be logged into your BRIDGES account to see the output. If you are logged into your account, the output will show up in your gallery.

2. What Visual Attributes are supported for Arrays?

The array you created in the first part of the tutorial uses default attributes and is pretty boring, but it gives you the basic structure of a BRIDGES program.

Next, we will style the array we just created. For arrays, you can set the color, opacity and label of the elements in the array. Check out the Bridges 'Element' and 'Color' classes that supports these attributes and also details the possible colors you can use and how to specify them.

The following code styles the array we created in part 1 and adds visual attributes. The visualization is shown below the code.

Java
C++
Python

3. Advanced Features.

In the last part of this tutorial, we show some advanced features with Arrays. This depends on the programming language, to some extent. For arrays, we can use the [] notation for accessing elements (suppported by C++), and iterators, range loops, etc. These make it more intuitive and convenient to traverse the data structure.

The following code illustrates these advanced features of arrays. The visualization is shown below the code.

Java
C++
Python

Well done! You’ve just created your doubly linked list!

Going Further

Array2D and Array3D are similar in terms of the features. Try these tutorials with these structures.

Check Bridges assignment page for array based assignments