Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.NoSuchElementException;
- import java.util.Scanner;
- /**
- * Course: EECS 114 Fall 2015
- *
- * First Name: Franklin Last Name: Hool Lab Section: 1A email address:
- * fhool@uci.edu
- *
- * Assignment: Lab 2 Filename : Main
- *
- * I hereby certify that the contents of this file represent my own original
- * individual work. Nowhere herein is there code from any outside resources such
- * as another individual, a website, or publishings unless specifically
- * designated as permissible by the instructor or TA.
- */
- public class Main {
- static FileReader reader;
- public static void main(String[] args) {
- // TODO: Input a file name from args[0] (it can be have a directory
- // appended to it) and open file to store in Scanner object.
- DoublyLinkedList<Integer> numLinkedList = new DoublyLinkedList<Integer>();
- numLinkedList.add(0, 1);
- System.out.println(numLinkedList.head.t);
- numLinkedList.add(0, 5);
- System.out.println(numLinkedList.head.t);
- numLinkedList.add(0, 6);
- System.out.println(numLinkedList.head.t);
- numLinkedList.remove(0);
- System.out.println(numLinkedList.head.t);
- System.out.println("size: "+numLinkedList.size());
- numLinkedList.remove(new Integer(5));
- System.out.println("HERE: "+numLinkedList.head.t);
- System.out.println("Size: "+ numLinkedList.size());
- System.out.println("Empty: "+numLinkedList.isEmpty());
- for(int i=0;i<numLinkedList.size();i++)
- {
- System.out.println(numLinkedList.get(i));
- }
- /*Scan all the lines of the file and add them to the Doubly Linked List
- * Traces exception when there are no more lines */
- DoublyLinkedList<String> stringLinkedList = new DoublyLinkedList<String>();
- try {
- Scanner fileScanner = new Scanner(new FileReader(args[0]));
- String line;
- while ((line = fileScanner.nextLine()) != null) {
- stringLinkedList.add(-1, line);
- System.out.println(line);
- }
- fileScanner.close();
- System.out.println(stringLinkedList.size());
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchElementException e) {
- System.out.println("No more Lines");
- e.printStackTrace();
- }
- // TODO: Add code to print the elements in numLinkedList
- // TODO: Add more test cases for DoublyLinkedList, which should contain
- // number elements inputted from Scanner object. Include test case for
- // String.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement