~jacks/dal-classwork unlisted

9b848a0d81e9f93744f7f35acd12cfe5cfd4216c — jacksarick 1 year, 1 day ago 533c1a6
they let us do all them this week
A CSCI 1110/POtD/week13/h/LinkedListDemo.java => CSCI 1110/POtD/week13/h/LinkedListDemo.java +32 -0
@@ 0,0 1,32 @@
import java.util.Scanner;
import java.util.ArrayList;

public class LinkedListDemo {
	public static void main(String[] args){
	
		//Read in all the cities into ArrayList and print
		Scanner sc = new Scanner(System.in);
		ArrayList<String> alist = new ArrayList<String>();
		String next = sc.next();
		while(!next.equals("*")){
			alist.add(0, next);
			next = sc.next();}
		System.out.print(alist);

		//Read even into Array and odd into LinkedList
		String[] array = new String[(int) (alist.size()/2 + Math.pow(0, 1 - alist.size()%2))];
		LinkedList llist = new LinkedList(); //^-- half the length, plus one if even
		int count = 0;
		for(String entry:alist){
			if(count % 2 == 0){
				array[(int) count/2] = entry;}
			else{llist.addToEnd(entry);}
			count++;}

		System.out.println();
		for(String e:array){
					System.out.print(e + " ");}

		System.out.println();
		llist.enumerate();}
}
\ No newline at end of file

A CSCI 1110/POtD/week13/t/LinkedListDemo.java => CSCI 1110/POtD/week13/t/LinkedListDemo.java +32 -0
@@ 0,0 1,32 @@
import java.util.Scanner;
import java.util.ArrayList;

public class LinkedListDemo {

	//Print ArrayList<String>
	public static void printAL(ArrayList<String> al){
		//Print (between brackets) all items,
		//followed by a comma except the final
		System.out.print("[");
		for(int i = 0; i < al.size(); i++){
			System.out.print(
				al.get(i)
				+ ((i == al.size()-1)?"":", "));}
		System.out.print("]\n");}
		
	public static void main(String[] args){
		//Read in all the cities and print
		Scanner sc = new Scanner(System.in);
		ArrayList<String> alist = new ArrayList<String>();
		String next = sc.next();
		while(!next.equals("*")){
			alist.add(0, next);
			next = sc.next();}
		printAL(alist);

		//Read cities into a linkedlist
		LinkedList llist = new LinkedList();
		for(String entry:alist){
			llist.addToFront(entry);}
		llist.enumerate();}
}
\ No newline at end of file

A CSCI 1110/POtD/week13/w/LinkedListDemo.java => CSCI 1110/POtD/week13/w/LinkedListDemo.java +30 -0
@@ 0,0 1,30 @@
import java.util.Scanner;

public class LinkedListDemo {
		
	public static void main(String[] args){

		//Read in all the cities
		Scanner sc = new Scanner(System.in);
		LinkedList llist = new LinkedList();
		String next = sc.next();
		while(!next.equals("*")){
		  llist.addToFront(next);
		  next = sc.next();}

		//print the llist
		llist.enumerate();

		//copy to list backwards
		int c = llist.count();
		String[] list = new String[c];
		Node curr = llist.getFront();
		for(int i = c - 1; i >= 0; i--){
			list[i] = curr.getData();
			curr = curr.getNext();}

		//print it
		System.out.println();
		for(String e:list){
			System.out.print(e + " ");}}
}
\ No newline at end of file