From charlesreid1

Line 24: Line 24:
* inputs X, outputs Y, with timing/profiling.
* inputs X, outputs Y, with timing/profiling.


==ArrayStack==
==Array-based Stack Implementation==


implementation of a stack using a fixed or variable size array.
implementation of a stack using a fixed or variable size array.
Array-based stack implementation: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/stacks/ArrayStack.java
==Array-based Queue Implementation==
The first array-based queue implementation is a data structure that uses a dynamically allocated array size to store data. ArrayQueue class: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/ArrayQueue.java
The second aray-based queue implementation is a data structure that uses a fixed array size, and throws a Full exception when full. ArrayQueueFS class: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/ArrayQueueFS.java
<pre>
import java.util.*;
import java.io.*;
class Empty extends ArrayIndexOutOfBoundsException{};
class Full extends ArrayIndexOutOfBoundsException{};
</pre>
==Linked List-based Queue Implementation==
The linked queue class uses a circular linked list to conserve memory for linked lists with high throughput.
See LinkedQueue class: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/LinkedQueue.java


=Flags=
=Flags=

Revision as of 05:36, 4 June 2017

Notes

Stacks and Queues in Java are implemented as part of the Collections library. Also implemented are Deques and priority queues.

Goodrich Java Chapter 6

Chapter 6 of Goodrich covers stacks and queues. These data structures can be implemented using array-based or link-based data structures. Thus, when covering data structures it's useful to start by covering array-based data structures that are dynamic, and their big-O cost of operations.

Queue - singly-linked list implementation - single head pointer - allows us to:

  • insert/remove at the head with O(1)
  • insert/remove at the tail with O(n)

Removing is O(n) because in a singly-linked list, we need the thing that links to tail.

Implementations

Stacks and queues can be implemented using various implementations:

  • fixed/variable size
  • contiguous/linked memory structure (array list vs linked list)
  • singly/circular/doubly linked lists
  • size of lists, size of objects and pointers

measurement/profiling of Java code for memory and performance, timing, etc.

  • inputs X, outputs Y, with timing/profiling.

Array-based Stack Implementation

implementation of a stack using a fixed or variable size array.

Array-based stack implementation: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/stacks/ArrayStack.java

Array-based Queue Implementation

The first array-based queue implementation is a data structure that uses a dynamically allocated array size to store data. ArrayQueue class: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/ArrayQueue.java

The second aray-based queue implementation is a data structure that uses a fixed array size, and throws a Full exception when full. ArrayQueueFS class: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/ArrayQueueFS.java

import java.util.*;
import java.io.*;

class Empty extends ArrayIndexOutOfBoundsException{};
class Full extends ArrayIndexOutOfBoundsException{};

Linked List-based Queue Implementation

The linked queue class uses a circular linked list to conserve memory for linked lists with high throughput.

See LinkedQueue class: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/LinkedQueue.java

Flags