Computer Science

Data Structures Algorithms

Temple University

### Question Description

import java.util.Iterator;

public class CircularLinkedList<E> implements Iterable<E> {

Node<E> tail;

int size; // BE SURE TO KEEP TRACK OF THE SIZE

// implement this constructor

}

// I highly recommend using this helper method

// Return Node<E> found at the specified index

// be sure to handle out of bounds cases

private Node<E> getNode(int index ) {

return null;

}

// attach a node to the end of the list

return false;

}

// Cases to handle

// out of bounds

// REMEMBER TO INCREMENT THE SIZE

public void add(int index, E item){

}

// remove must handle the following cases

// out of bounds

// removing the only thing in the list

// removing the first thing in the list (need to adjust the last thing in the list to point to the beginning)

// removing the last thing

// removing any other node

// REMEMBER TO DECREMENT THE SIZE

public E remove(int index) {

return null;

}

// Turns your list into a string

// Useful for debugging

public String toString(){

StringBuilder result = new StringBuilder();

if(size == 0){

return "";

}

if(size == 1) {

}

else{

do{

result.append(current.item);

result.append(" ==> ");

current = current.next;

}

return result.toString();

}

public Iterator<E> iterator() {

return new ListIterator<E>();

}

// provided code for different assignment

// you should not have to change this

// change at your own risk!

// this class is not static because it needs the class it's inside of to survive!

private class ListIterator<E> implements Iterator<E>{

Node<E> nextItem;

Node<E> prev;

int index;

@SuppressWarnings("unchecked")

//Creates a new iterator that starts at the head of the list

public ListIterator(){

index = 0;

}

// returns true if there is a next node

// this is always should return true if the list has something in it

public boolean hasNext() {

// TODO Auto-generated method stub

return size != 0;

}

// advances the iterator to the next item

// handles wrapping around back to the head automatically for you

public E next() {

// TODO Auto-generated method stub

prev = nextItem;

nextItem = nextItem.next;

index = (index + 1) % size;

return prev.item;

}

// removed the last node was visted by the .next() call

// for example if we had just created a iterator

// the following calls would remove the item at index 1 (the second person in the ring)

// next() next() remove()

public void remove() {

int target;

target = size - 1;

} else{

target = index - 1;

index--;

}

}

}

// It's easiest if you keep it a singly linked list

// SO DON'T CHANGE IT UNLESS YOU WANT TO MAKE IT HARDER

private static class Node<E>{

E item;

Node<E> next;

public Node(E item) {

this.item = item;

}

}

public static void main(String[] args){

}

}

public class SolitaireEncryption {

public static char encryptChar(char letter, int key) {

int value = letter - 'a';

int encryptedValue = (value + key) % 26;

char encryptedChar = (char) (encryptedValue+'a');

return encryptedChar;

}

public static char decryptChar(char letter, int key) {

int value = letter - 'a';

int decryptedValue = (value + (26-key)) % 26;

char decryptedChar = (char) (decryptedValue+'a');

return decryptedChar;

}

public int getKey(CircularLinkedList<Integer> deck){ // calls the steps methods

return -1;

}

}

}

}

}

return -1;

}

public static void main(String[] args) {