Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Assignment 6 CSIT 221 – Computer Science 2 Spring 2018

Due May 1st, 2018 at the beginning of class.

Please submit the code for each problem on onCourse in a single text file. In addition, a printed copy of the assignment
(in a readable format) is due at the beginning of the class on the due date.
Problems 1 and 2. Consider the linked list we implemented in class
template <class T>
struct nodeType
{
T data;
nodeType<T> *next;
};

template <class T>


class myLL
{
public:
myLL(); //the default constructor
void insert(T); //insert at the beginning of the list
void print();
void insertS(T x); //insert x immediately before the first element that is bigger than x
int getSize() { return size; }
bool isEmpty() { return head==nullptr; }
bool remove(T); //remove the first occurrence of the specified element
bool search(T x); //returns true if x is in the list;

void split(myLL<T> &L1, myLL<T> &L2);


//splits the list into two lists L1 and L2
//where L1 is contains the first size/2 elements,
// and the second list contains the rest of the elements
//at the end of the operation the original list must be empty
// e.g. if the original list L={21,1,12,34,56},
// then after the operation L={}, L1={21,1,12}, L2={34,56};

int numPosElements();
//returns the number of elements for which the field data>0
//note this will only work for those list that the comparison data>0 is defined
private:
nodeType<T>* head;
int size;

};
Problem 1 (20 points) Implement the function split for the class above.

Problem 2 (20 points) Implement the function numPosElement for the class above.

Problem 3 (20 points) Write a piece of code that given an STL (standard template library) stack of doubles, it will remove
the negative entries from the stack. The order of the remaining entries must be preserved.

Problem 4 (20 points) Write a piece of code that given an STL queue of strings, it will remove the strings that start with a
digit (0-9) from the queue. The order of the remaining entries must be preserved.

Problem 5 (20 points) Write a function that will test if the contents of an STL queue of characters form a palindrome. A
palindrome is a string that reads the same forward and backward (e.g. kayak, madam, dad).

You might also like