List ADT and Implementations

A possible List ADT

Possible List Implementations

Array Implementation

#define MAXLEN 50

typedef int Position;

typedef struct {
   Element data[MAXLEN];
   int length;
} List;


Two Array Implementation


#define MAXLEN 50

typedef int Position;

typedef struct {
   Element data[MAXLEN];
   int     next[MAXLEN];
   int length;
   Position first;
   Position last;
   Position free;
} List;

Linked List Implementation

typedef struct node {
   Element data;
   struct node *next;
} *Position;

typedef struct {
   Position first;
   Position last;
   int length;
} List;

Double Linked List Implementation

typedef struct node {
   Element data;
   struct node *next;
   struct node *prev;
} *Position;

typedef struct {
   Position first;
   Position last;
   int length;
} List;

Runtime of List ADT given an Implementation

ArrayTwo ArraysLinked ListDouble Linked List
MakeEmpty O(1) O(1) O(n) O(n)
Find O(n) O(n) O(n) O(n)
FindKth O(1) O(n) O(n) O(n)
ElementAt O(1) O(1) O(1) O(1)
Size O(1) O(1) O(1) O(1)
InsertElementAfter O(n) O(1) O(1) O(1)
InsertElementBefore O(n) O(n) O(n) O(1)
DeleteElementAt O(n) O(n) O(n) O(1)
DeleteElementAfter O(n) O(1) O(1) O(1)
Previous O(1) O(n) O(n) O(1)
Next O(1) O(1) O(1) O(1)
Print O(n) O(n) O(n) O(n)
AppendList O(n) O(n) O(1) O(1)