Giter Club home page Giter Club logo

a4nodequeue's Introduction

CSC 340 Assignment 4
Implementation of Node:

Node is a simple data container that allows single linkage.

class Node {
public:
    Node(int value);
    Node *next;
    int value;
};

All members are public because the class is not intended for use outside the this library.

Queue is implemented as a singly linked list, the Node's "next" member allows the elements of Queue to "link" to eachother. 


void Queue::enqueue(int value){
    
  if(this->isEmpty()){
      beginning = new Node(value);
      end = beginning;
  }
  else
  {
      end->next = new Node(value);
      end = end->next;
  }
  
  count ++;
}

int Queue::dequeue(void){
  if( this->isEmpty() )
  {
      return EMPTY_VALUE;
  }
  
  int ret = beginning->value;

  Node *toBeDestroyed = beginning;
  
  beginning = beginning->next;

  delete(toBeDestroyed);
    
  count --;
	
  return ret;
}


output:


Creating QueueTest
--- Testing queue is not empty ---
PASS

--- Testing queue size is 30 ---
PASS

--- Testing queue front is 6203 ---
PASS

--- Testing queue size is 30 ---
PASS

--- Testing dequeue should be 6203 ---
PASS

--- Testing queue size is 29 ---
PASS

--- Testing queue front is 812 ---
PASS

--- Testing clearing the queue (isEmpty and dequeue) ---
PASS

--- Testing queue is empty ---
PASS

--- Testing default value returned when dequeue called on empty Queue ---
PASS

Destroyed QueueTest

a4nodequeue's People

Contributors

awmiller avatar

Watchers

James Cloos avatar  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.