Git Product home page Git Product logo

deques-and-randomized-queues's Introduction

This is Assignment 2 from Princeton's Algorithms Part I course, made using Eclipse, version: Neon.2 Release (4.6.2).*

Description

This program implemented a double-ended queue (deque) and a randomized queue.

A deque is a generalization of a stack and a queue that supports both adding and removing items from the front and the end of the data structure. It is implemented using a Doubly Linked List. The Deque supports methods such as getting it's size, getting if it's empty or not, or returning an iterator through the contents of the data structure.

A randomized queue is similar to a stack and queue, except that the item removed is chosen uniformly at random from all items in the data structure. For this reason, it is implemented using a resizable array. The RandomizedQueue supports methods such as sampling a random item in the data structure, removing an item, getting it's size, and getting if it's empty or not. There is also an iterator() method which returns a new iterator in random order through the contents of the RandomizedQueue.

The Permutation class reads in a sequence of Strings from a given .txt file(txt-file-name), and prints the given number (num-strings-to-print) of them uniformly at random, while only printing each String at most once. Permutation utilizes RandomizedQueue to accomplish this.

Unit testing done for Deque and RandomizedQueue classes using JUnit.

Deque.java and RandomizedQueue.java both support main() methods that print simple demonstrations to the console.

Command Line Instructions for Permutation

cd src/

Windows:

Compile:
javac -cp ".;../lib/algs4.jar;../lib/hamcrest-core-1.3.jar;../lib/junit-4.12.jar" *.java

Run:
java -cp ".;../lib/algs4.jar;../lib/hamcrest-core-1.3.jar;../lib/junit-4.12.jar" Permutation <num-strings-to-print> < ../testing/<txt-file-name>

Mac:

Compile:
javac -cp ".:../lib/algs4.jar:../lib/hamcrest-core-1.3.jar:../lib/junit-4.12.jar" *.java

Run:
java -cp ".:../lib/algs4.jar:../lib/hamcrest-core-1.3.jar:../lib/junit-4.12.jar" Permutation <num-strings-to-print> < ../testing/<txt-file-name>

Command Line Instructions for Deque Demo

(Simply replace Deque with RandomizedQueue to see a RandomizedQueue demonstration)

cd src/

Windows:

Compile:
javac -cp ".;../lib/algs4.jar" Deque.java

Run:
java -cp ".;../lib/algs4.jar" Deque

Mac:

Compile:
javac -cp ".:../lib/algs4.jar" Deque.java

Run:
java -cp ".:../lib/algs4.jar" Deque

deques-and-randomized-queues's People

Contributors

gregdardis avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.