YCP Logo Assignment 1: Implement a Generic Stack

Due: Thursday, Jan 28th by 11:59 PM

Getting started

Download CS350_Assign1.zip. Import it into your Eclipse workspace (File->Import...->General->Existing projects into workspace->Archive File). You will see a project called CS350_Assign1 in the Package Explorer.

Do not use java.util

In this course, you are required to implement all data structures from scratch. Do not use any of the classes in the java.util package.

Do not copy code from textbook or other sources

Some assignments in this course may involve data structures which are implemented by source code in the textbook. And, of course, lots of code is available from web sites and other sources.

I expect you to implement all data structures and algorithms from scratch, using your knowledge of how they work. Do not copy code from any source, including the textbook.

Your task

Implement a generic stack class called MyStack. It should implement the YStack<E> interface (provided in the assignment skeleton.)

All of the methods defined in the YStack interface must complete in O(1) average time.


  1. Use an array to store the elements in the stack. Grow the array as necessary as elements are added. (Make sure the size of the storage array doubles at each expansion so that the amortized time to add an element is O(1).)
  2. Use a singly-linked list to store elements in the stack. You will need to think about how to add and remove elements so that the push and pop operations are O(1).

Add unit tests to the MyStackTest JUnit test class to thoroughly test your stack implementation. Think carefully about some of the special cases that your code may encounter.


Your grade for the assignment will be determined as follows:

  • Correctness of stack implementation: 40%
  • Efficiency of stack operations (all should be O(1) average): 20%
  • Comprehensiveness of JUnit tests: 40%


Export your finished project to a zip file (right-click on the project, then Export...->Archive File). Upload the zip file to the marmoset server as project assign1. The server URL is


IMPORTANT: after uploading, you should download a copy of your submission and double-check it to make sure that it contains the correct files. You are responsible for making sure your submission is correct. You may receive a grade of 0 for an incorrectly submitted assignment.