SE250:HTTB:Array-based Lists:Introduction

From Marks Wiki
Jump to navigation Jump to search
Previous Page Contents Next Page



Introduction

An array-based list is a data structure that stores elements in a contiguous block of memory. The end of the list provides expansion space that can grow as new elements are added.

  • The capacity of an array-based list is the number of elements in the block of memory.
  • This size (or length) is the number of elements currently in the array list.

An array-based list can be made of any data type using structures (see ABL Structure below).

The new elements can be added into the expansion space in two different ways.

  • Put (inserts a specified value at a specified index).
  • Push (inserts a specified value at the end of the array. (see Insertion below)

An array list can be resized by altering the capacity either by multiplying or by incrementing the growth capacity (see Dynamically resizing array).

Real Life Example: An Absolute n00b's Guide

<html>

<embed src="http://www.orlybird.com/SE250/HTTB/arraylists.swf" height="400" width="500" />

</html>

Created by: Sshi080 21:11, 6 June 2008 (NZST)

ABL Structure

<HTML> <IMG SRC="http://www.geocities.com/braydondunnit/SOFTENG250/1.jpg"> </HTML>

The structure of a Array-Based List is defined by the following code:

typedef int element_t;	        /* choose your favourite type, int is chosen in this case*/

typedef
struct {
  element_t *arr;		/* a pointer to the start of the array */
  int capacity;	                /* total number of elements available to use*/
  int length;			/* number of positions used, ranging from 0 to capacity */
} ArrayList;



Previous Page Contents Next Page