Chapter 5 - A Simple Dynamic Linked List (Holding Strings)

Size: px
Start display at page:

Download "Chapter 5 - A Simple Dynamic Linked List (Holding Strings)"

Transcription

1 Chapter 5 - A Simple Dynamic Linked List (Holding Strings) Very Simple Link Class Holding String Data and Reference to Next Link (Version 1) public class Link{ private String data; private Link next; public Link(String newdata){ data = newdata; next = null; public String getdata() { return data; public void setdata(string data) { this.data = data; public Link getnext() { return next; public void setnext(link next) { this.next = next; public void showdata(){ System.out.println("Data:" + data + " Next:" + next); List Driver (Version 1) public class LinkedListDriver { /** * making/testing the HomeMadeLinkedList class (Step 1 just a few links) */ public static void main(string[] args) { Link n1 = new Link("AAA"); Link n2 = new Link("BBB"); Link n3 = new Link("CCC"); n1.setnext(n2); n2.setnext(n3); System.out.println( "\nn1: " + n1); n1.showdata(); System.out.println( "\nn2: " + n2); n2.showdata(); System.out.println( "\nn3: " + n3); n3.showdata(); System.out.println("\n\nTraversing the CHAIN"); Link n = n1; while (n!= null){ n.showdata(); n = n.getnext();

2 Console n1: Data:AAA n2: Data:BBB n3: Data:CCC Next:null Traversing the CHAIN Data:AAA Data:BBB Data:CCC Next:null

3 A Better Link Class Generic Link: GLink Holding Data of Any Type (Version 2) public class GLink<E>{ private E data; private GLink next; public GLink(E newdata){ data = newdata; next = null; public E getdata() { return data; public void setdata(e data) { this.data = data; public GLink getnext() { return next; public void setnext(glink next) { this.next = next; public void showdata(){ System.out.println("Data Class>>> " + data.getclass().getname() ); System.out.println(" Data:" + data.tostring() + "\t Next: " + next); if (data.getclass().getname().equals("cis265.matos.person")) { ((Person) data).showdata(); Driver. Testing the new GLink class (Version 2) public class LinkedListDriver { /** * GLinks hold arbitrary data connecting links by hand ClassNotFoundException */ public static void main(string[] args) throws ClassNotFoundException { // GLink n1 = new GLink("AAA"); // GLink n2 = new GLink(123); // GLink n3 = new GLink(123.99); //Not a good idea to mix types in the chain... Person p1 = new Person("Macarena", " "); GLink<String> n1 = new GLink<String>("AAA"); GLink n2 = new GLink(222); GLink<Person> n3 = new GLink<Person>(p1); // // a chain of Person objects // GLink<Person> n1 = new GLink<Person>(new Person("person1", " "));

4 // GLink<Person> n2 = new GLink<Person>(new Person("person2", " ")); // GLink<Person> n3 = new GLink<Person>(new Person("person3", " ")); //interconnecting nodes by hand n1.setnext(n2); n2.setnext(n3); // showing the GLinks System.out.println( "\nn1: " + n1); n1.showdata(); System.out.println( "\nn2: " + n2); n2.showdata(); System.out.println( "\nn3: " + n3); n3.showdata(); //TODO: move the logic for detecting class type // and printing to the GLink<E> class System.out.println("\n\nTraversing the CHAIN"); Person p; GLink n = n1; Object obj; while (n!= null){ n.showdata(); obj = n.getdata(); // ugly syntax to detect at run-time an object s class type: // if (obj.getclass().getname().equals("cis265.matos.person")) // The following is equivalent (and much simpler) if (obj instanceof Person) { p = (Person) n.getdata(); System.out.print(" >>> " ); p.showdata(); n = n.getnext(); Console n1: cis265.matos.glink@42e816 Data:AAA Next:cis265.matos.GLink@9304b1 n2: cis265.matos.glink@9304b1 Data:222 Next:cis265.matos.GLink@190d11 n3: cis265.matos.glink@190d11 Data:cis265.matos.Person@a90653 Next:null Name: Macarena Phone: Traversing the CHAIN Data:AAA Next:cis265.matos.GLink@9304b1 Data:222 Next:cis265.matos.GLink@190d11 Data:cis265.matos.Person@a90653 Next:null Name: Macarena Phone: >>> Name: Macarena Phone:

5 HomeMadeDynamicList Application (singly-linked) (Version 3) Method insertfirst(avalue) deletefirst() insertlast(avalue) deletelast() insertordered(avalue) search(avalue) deletelink(avalue) isempty() deleteall() showlist() Description Place avalue as first element of the list Remove first element of the list Place avalue as last element of the list Remove last element of the list Insert avalue in between links which are <= and > than it Return location in list of a link having data equal to avalue Remove link holding data equal to avalue Return true if list is empty, false otherwise Delete all nodes in the list Display on console links in the list GLink<E> Class public class GLink<E>{ private E data; private GLink<E> next; public GLink(E newdata){ data = newdata; next = null; public E getdata() { return data; public void setdata(e data) { this.data = data; public GLink<E> getnext() { return next; public void setnext(glink<e> next) { this.next = next; public void showdata(){ System.out.println(" Data:" + data + " Next:" + next); System.out.println("Data Class>>> " + data.getclass().getname() );

6 HomeMadeDynamicList class (Holding Control Variables and Basic List Operations) public class HomeMadeDynamicList<E> { // ///////////////////////////////////////////////// // dynamic single linked list // TODO: sortlist(), deletevalue(avalue) // clearall(), isempty(), search(avalue) // ///////////////////////////////////////////////// private GLink<E> mhead; private GLink<E> mtail; int mcount; // ///////////////////////////////////////////// public HomeMadeDynamicList() { mhead = mtail = null; mcount = 0; public GLink<E> getfirst() { return mhead; public void setfirst(glink<e> mhead) { this.mhead = mhead; public GLink<E> getlast() { return mtail; public void setlast(glink<e> mtail) { this.mtail = mtail; public int getcount() { return mcount; public void setcount(int mcount) { this.mcount = mcount; public void insertfirst(e newvalue) { GLink<E> node = new GLink<E>(newValue); if (mcount == 0) { mhead = mtail = node; mcount = 1; else { node.setnext(mhead); mhead = node; mcount++; public void insertlast(e newvalue) { GLink<E> node = new GLink<E>(newValue); if (mcount == 0) {

7 mhead = mtail = node; mcount = 1; else { mtail.setnext(node); mtail = node; mcount++; // ///////////////////////////////////////////////// public void deletefirst() throws Exception { if (mcount == 0) throw new Exception("ERROR- nothing to delete!"); if (mcount == 1) { mhead = mtail = null; mcount = 0; else { mhead = mhead.getnext(); mcount--; public void deletelast() throws Exception { GLink<E> current, previous; if (mcount == 0) throw new Exception("ERROR- nothing to delete!"); if (mcount == 1) { mhead = mtail = null; mcount = 0; else { mcount--; current = previous = mhead; while (current!= mtail) { previous = current; mtail = previous; mtail.setnext(null); // ///////////////////////////////////////////////// public static <E> E createanyobject(class<e> cls) { E ret = null; try { ret = cls.newinstance(); catch (Exception e) { // --- Exception Handling return ret; public void showlist() { System.out.println("\nmHead: \t" + mhead + "\nmtail: \t" + mtail + "\nmcount: \t" + mcount); GLink<E> current = this.mhead; // OK this is not the best solution (yet) // it works because we know that E represents

8 // Person. We'll (try to) solve this problem later. Person p = null; Object obj; while (current!= null) { obj = current.getdata(); System.out.println("Data: " + obj + "\t" + "LocNext: " + current); if (obj instanceof Person) { p = (Person) obj; p.showdata(); // showdata // ======================================================= // searching by person's phone public GLink<E> search(string searchphoneno) { Person p; GLink<E> current = mhead; while (current!= null) { p = (Person) current.getdata(); if (p.getmphone().compareto(searchphoneno) == 0) return current; return null; public boolean deleteglink(string phonenumber) { GLink<E> current = mhead; GLink<E> previous = mhead; Person p; while (current!= null) { p = (Person) current.getdata(); if (p.getmphone().compareto(phonenumber) == 0) { if (mcount == 1) { mhead = mtail = null; if (mhead == current) { mhead = current.getnext(); if (mtail == current) { mtail = previous; previous.setnext(current.getnext()); mcount--; return true; previous = current; return false; public void deleteall() { mhead = mtail = null; mcount = 0; System.gc();

9 public void displayinreverse() { GLink<E> current; int n; HomeMadeDynamicList<E> templist = new HomeMadeDynamicList<E>(); for (int i = 0; i < mcount; i++) { current = mhead; for (int j = 1; j < mcount - i; j++) { templist.insertlast(current.getdata()); System.out.println("<<<< reverse >>>>"); templist.showlist(); public boolean isempty() { return (mcount == 0); public void reverse() { HomeMadeDynamicList<E> temp = new HomeMadeDynamicList<E>(); E mtailvalue; try { while (!this.isempty()) { mtailvalue = this.mtail.getdata(); this.deletelast(); temp.insertlast(mtailvalue); this.mhead = temp.mhead; this.mtail = temp.mtail; this.mcount = temp.mcount; catch (Exception e) { System.out.println(e.getMessage()); // reverse // //////////////////////////////////////////////// public void insertphoneorder(e newnamephone) { // //////////////////////////////////////// // using Comparator interface GLink<E> lnk; Person p1, p2; if (mcount == 0) { p1 = (Person) mhead.getdata(); p2 = (Person) newnamephone; if (Person.comparePhones.compare(p1, p2) > 0) { p1 = (Person) mtail.getdata(); if (Person.comparePhones.compare(p1, p2) < 0) { this.insertlast(newnamephone); GLink<E> current = mhead; GLink<E> previous = mhead;

10 boolean keepgoing = true; while ((current!= null) && keepgoing) { p1 = (Person) current.getdata(); if (Person.comparePhones.compare(p1, p2) < 0) { previous = current; else { keepgoing = false; GLink<E> newnode = new GLink<E>(newNamePhone); newnode.setnext(current); previous.setnext(newnode); mcount++; // insertphoneorder // //////////////////////////////////////////////// public void insertalphabeticorder(e newnamephone) { // using Person's name to decide order GLink<E> lnk; Person p1, p2; if (mcount == 0) { p1 = (Person) mhead.getdata(); p2 = (Person) newnamephone; if (p1.getmname().compareto(p2.getmname()) > 0) { p1 = (Person) mtail.getdata(); if (p1.getmname().compareto(p2.getmname()) < 0) { this.insertlast(newnamephone); GLink<E> current = mhead; GLink<E> previous = mhead; boolean keepgoing = true; while ((current!= null) && keepgoing) { p1 = (Person) current.getdata(); if (p1.getmname().compareto(p2.getmname()) < 0) { previous = current; else { keepgoing = false; GLink<E> newnode = new GLink<E>(newNamePhone); newnode.setnext(current); previous.setnext(newnode); mcount++; // insertphoneorder // ////////////////////////////////////////////////// public void insertalphabeticorderv2(e newnamephone) { // using Comparable interface to compare two Person's name // The following version of the reverse method is // equivalent to the previous code but uses the

11 // compareto method of the Comparable interface // (observe that you must provide the compareto code) GLink<E> lnk; Person p1, p2; if (mcount == 0) { p1 = (Person) mhead.getdata(); p2 = (Person) newnamephone; if (p1.compareto(p2) > 0) { p1 = (Person) mtail.getdata(); if (p1.compareto(p2) < 0) { this.insertlast(newnamephone); GLink<E> current = mhead; GLink<E> previous = mhead; boolean keepgoing = true; while ((current!= null) && keepgoing) { p1 = (Person) current.getdata(); if (p1.compareto(p2) < 0) { previous = current; else { keepgoing = false; GLink<E> newnode = new GLink<E>(newNamePhone); newnode.setnext(current); previous.setnext(newnode); mcount++; // insertphoneorderv2 HomeMadeDynamicListDriver public class LinkedListDriverDos { /** * Putting all pieces together (GLink, HomeMadeLinkedList, Driver) * Inserting Person objects */ public static void main(string[] args) { // a chain of Person objects GLink<Person> p = null; HomeMadeDynamicList<Person> lst = new HomeMadeDynamicList<Person>(); lst.insertlast(new Person("person1", " ")); lst.insertlast(new Person("person2", " ")); lst.insertlast(new Person("person3", " ")); lst.insertlast(new Person("person4", " ")); lst.showlist(); System.out.println();

12 p = lst.getfirst(); while(p!= null){ System.out.println("\nLoc: " + p); p.getdata().showdata(); System.out.println(" Next: " + p.getnext()); p = p.getnext(); //while // locate person using phone number GLink<Person> lnksought = lst.search(" "); Person p2; if (lnksought == null) System.out.println("\nSorry not found"); else { System.out.println("\nFound"); lnksought.showdata(); p2 = (Person)lnkSought.getData(); p2.showdata(); // deleting a node using phone number System.out.println("\nDeleting a Node:"); lst.deleteglink(" "); lst.showlist(); // adding a new person in alphabetic order System.out.println("\nInserting in Alphabetic Order:"); lst.insertalphabeticorder(new Person("person5", " ")); lst.insertalphabeticorder(new Person("person0", " ")); lst.insertalphabeticorder(new Person("person3", " ")); lst.showlist(); // reversing the list System.out.println("\nReversing:"); lst.reverse(); lst.showlist(); Console mhead: cis265.matos.glink@42e816 mtail: cis265.matos.glink@9304b1 mcount: 4 Data: cis265.matos.person@190d11 LocNext: cis265.matos.glink@42e816 Name: person1 Phone: Data: cis265.matos.person@a90653 LocNext: cis265.matos.glink@de6ced Name: person2 Phone: Data: cis265.matos.person@c17164 LocNext: cis265.matos.glink@1fb8ee3 Name: person3 Phone: Data: cis265.matos.person@61de33 LocNext: cis265.matos.glink@9304b1 Name: person4 Phone: Loc: cis265.matos.glink@42e816 Name: person1 Phone: Next: cis265.matos.glink@de6ced Loc: cis265.matos.glink@de6ced

13 Name: person2 Phone: Next: Loc: Name: person3 Phone: Next: Loc: Name: person4 Phone: Next: null Found Data Class>>> cis265.matos.person Name: person3 Phone: Deleting a Node: mhead: cis265.matos.glink@42e816 mtail: cis265.matos.glink@9304b1 mcount: 3 Data: cis265.matos.person@190d11 LocNext: cis265.matos.glink@42e816 Name: person1 Phone: Data: cis265.matos.person@a90653 LocNext: cis265.matos.glink@de6ced Name: person2 Phone: Data: cis265.matos.person@61de33 LocNext: cis265.matos.glink@9304b1 Name: person4 Phone: Inserting in Alphabetic Order: mhead: cis265.matos.glink@14318bb mtail: cis265.matos.glink@ca0b6 mcount: 6 Data: cis265.matos.person@10b30a7 LocNext: cis265.matos.glink@14318bb Name: person0 Phone: Data: cis265.matos.person@190d11 LocNext: cis265.matos.glink@42e816 Name: person1 Phone: Data: cis265.matos.person@a90653 LocNext: cis265.matos.glink@de6ced Name: person2 Phone: Data: cis265.matos.person@1a758cb LocNext: cis265.matos.glink@1b67f74 Name: person3 Phone: Data: cis265.matos.person@61de33 LocNext: cis265.matos.glink@9304b1 Name: person4 Phone: Data: cis265.matos.person@69b332 LocNext: cis265.matos.glink@ca0b6 Name: person5 Phone: Reversing: mhead: cis265.matos.glink@173a10f mtail: cis265.matos.glink@530daa mcount: 6 Data: cis265.matos.person@69b332 LocNext: cis265.matos.glink@173a10f Name: person5 Phone: Data: cis265.matos.person@61de33 LocNext: cis265.matos.glink@a62fc3 Name: person4 Phone: Data: cis265.matos.person@1a758cb LocNext: cis265.matos.glink@89ae9e Name: person3 Phone: Data: cis265.matos.person@a90653 LocNext: cis265.matos.glink@1270b73 Name: person2 Phone: Data: cis265.matos.person@190d11 LocNext: cis265.matos.glink@60aeb0 Name: person1 Phone: Data: cis265.matos.person@10b30a7 LocNext: cis265.matos.glink@530daa Name: person0 Phone:

14 A Better Person Class Implementing the Comparable Interface (Version 4) In order to compare two Person objects we must (arbitrarily) decide how to establish order among those two objects. In our example, are we classifying according to name or phone number? Once we decide what criteria should be used, we could write this policy in the CompareTo method of the Person class. CompareTo() is the only method of the Comparable interface. For more information on the Comparable Interface read the notes at: public class Person implements Comparable<Person> { private String mname; private String mphone; public Person(String mname, String mphone) { super(); this.mname = mname; this.mphone = mphone; public String getmname() { return mname; public void setmname(string mname) { this.mname = mname; public String getmphone() { return mphone; public void setmphone(string mphone) { this.mphone = mphone; public void showdata(){ System.out.println(" Name: " + mname +" Phone: " + mphone); ///////////////////////////////////////////////// // needed to implement the Comparable interface // uses person's name to establish public int compareto(person otherperson) { String thisname = this.getmname(); String othername = otherperson.getmname(); return (thisname.compareto(othername)); The new implementation of the Person class will have an impact on direct comparison of two Person objects. For instance the method insertalphabeticalorder( ) in the HomeMadeDynamicList class can be implemented as follows: Observe the use of the overridden CompareTo( ) method in the conditional statement

15 if (p1.compareto(p2) > 0 ). public void insertalphabeticorder(e newnamephone) { ////////////////////////////////////////// // using Comparable interface GLink<E> lnk; Person p1, p2; if (mcount == 0) { p1 = (Person) mhead.getdata(); p2 = (Person) newnamephone; if (p1.compareto(p2) > 0) { p1 = (Person) mtail.getdata(); if (p1.compareto(p2) < 0) { this.insertlast(newnamephone); GLink<E> current = mhead; GLink<E> previous = mhead; boolean keepgoing = true; while ((current!= null) && keepgoing) { p1 = (Person) current.getdata(); if (p1.compareto(p2) < 0) { previous = current; else { keepgoing = false; GLink<E> newnode = new GLink<E>(newNamePhone); newnode.setnext(current); previous.setnext(newnode); mcount++; // insertalphabeticorder

16 Enhancing the Person Class Implementing Comparator Interface (Version 5) This time we want to have both possiblilities of orderin person objects (by name, and by phone number). To accomplish this goal we implement two new static Comparator.compare methods in the person class. import java.util.comparator; public class Person implements Comparable<Person> { private String mname; private String mphone; public Person(String mname, String mphone) { super(); this.mname = mname; this.mphone = mphone; public String getmname() { return mname; public void setmname(string mname) { this.mname = mname; public String getmphone() { return mphone; public void setmphone(string mphone) { this.mphone = mphone; public void showdata(){ System.out.println(" Name: " + mname +" Phone: " + mphone); ///////////////////////////////////////////////// // needed to implement the Comparable interface // uses person's name to establish public int compareto(person otherperson) { String thisname = this.getmname().touppercase(); String othername = otherperson.getmname().touppercase(); return (thisname.compareto(othername)); public static Comparator<Person> comparenames = new Comparator<Person>() { public int compare(person p1, Person p2){ return(p1.compareto(p2)); ; public static Comparator<Person> comparephones = new Comparator<Person>() { public int compare(person p1, Person p2){ return(p1.getmphone().compareto(p2.getmphone())); ; The new method could be used to support an insertion of person objects driven by either name or phone. For instance we could add the following insertphoneorder() method to the HomeMadeDynamicList class. public void insertphoneorder(e newnamephone) { ////////////////////////////////////////// // using Comparator interface

17 GLink<E> lnk; Person p1, p2; if (mcount == 0) { p1 = (Person) mhead.getdata(); p2 = (Person) newnamephone; if (Person.comparePhones.compare(p1, p2) > 0) { p1 = (Person) mtail.getdata(); if (Person.comparePhones.compare(p1, p2) < 0) { this.insertlast(newnamephone); GLink<E> current = mhead; GLink<E> previous = mhead; boolean keepgoing = true; while ((current!= null) && keepgoing) { p1 = (Person) current.getdata(); if (Person.comparePhones.compare(p1, p2) < 0) { previous = current; else { keepgoing = false; GLink<E> newnode = new GLink<E>(newNamePhone); newnode.setnext(current); previous.setnext(newnode); mcount++; // insertphoneorder

Fundamental Java Methods

Fundamental Java Methods Object-oriented Programming Fundamental Java Methods Fundamental Java Methods These methods are frequently needed in Java classes. You can find a discussion of each one in Java textbooks, such as Big Java.

More information

CIS 265 Lecture Notes Binary Trees V. Matos DRIVER1. package csu.matos; public class Driver1 {

CIS 265 Lecture Notes Binary Trees V. Matos DRIVER1. package csu.matos; public class Driver1 { CIS 265 Lecture Notes Binary Trees V. Matos DRIVER1 public class Driver1 { /** * GOAL: create a simple binary tree using custom-made linked nodes * nodes carry Integer numbers */ public static void main(string[]

More information

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12 CS 151 Linked Lists, Recursively Implemented 1 2 Linked Lists, Revisited Recall that a linked list is a structure that represents a sequence of elements that are stored non-contiguously in memory. We can

More information

PASS4TEST IT 인증시험덤프전문사이트

PASS4TEST IT 인증시험덤프전문사이트 PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from

More information

COE318 Lecture Notes Week 9 (Oct 31, 2011)

COE318 Lecture Notes Week 9 (Oct 31, 2011) COE318 Software Systems Lecture Notes: Week 9 1 of 12 COE318 Lecture Notes Week 9 (Oct 31, 2011) Topics Casting reference variables equals() and hashcode() overloading Collections and ArrayList utilities

More information

Announcements. Prelude (2) Prelude (1) Data Structures and Information Systems Part 1: Data Structures. Lecture 6: Lists.

Announcements. Prelude (2) Prelude (1) Data Structures and Information Systems Part 1: Data Structures. Lecture 6: Lists. Announcements MODULE WEB-SITE: http://www.csc.liv.ac.uk/ michele/teaching/comp102/comp102.html FIRST ASSIGNMENT DEADLINE: Wednesday, February 1st, 14.30, LAB 7 Boxes (late submissions to be left in the

More information

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,

More information

Introduction to Computer Science II CS S-18 Linked Lists

Introduction to Computer Science II CS S-18 Linked Lists Introduction to Computer Science II CS112-2012S-18 Linked Lists David Galles Department of Computer Science University of San Francisco 18-0: Linked Lists Linked List node Data Pointer to the next element

More information

Linked Lists. private int num; // payload for the node private Node next; // pointer to the next node in the list }

Linked Lists. private int num; // payload for the node private Node next; // pointer to the next node in the list } Linked Lists Since a variable referencing an object just holds the address of the object in memory, we can link multiple objects together to form dynamic lists or other structures. In our case we will

More information

Introduction. Reference

Introduction. Reference Introduction Data Structures - Linked Lists 01 Dr TGI Fernando 1 2 Problems with arrays Unordered array - searching is slow, deletion is slow Ordered array - insertion is slow, deletion is slow Arrays

More information

Task 2 What is printed out when the code is executed?

Task 2 What is printed out when the code is executed? Task 1 What is printed out when the code is executed? public class Class1 { public static void main(string[] args) { int array[] = {14,5,7; for (int counter1 = 0; counter1 < array.length; counter1++) {

More information

1. ArrayList and Iterator in Java

1. ArrayList and Iterator in Java 1. ArrayList and Iterator in Java Inserting elements between existing elements of an ArrayList or Vector is an inefficient operation- all element after the new one must be moved out of the way which could

More information

1. Stack Implementation Using 1D Array

1. Stack Implementation Using 1D Array Lecture 5 Stacks 1 Lecture Content 1. Stack Implementation Using 1D Array 2. Stack Implementation Using Singly Linked List 3. Applications of Stack 3.1 Infix and Postfix Arithmetic Expressions 3.2 Evaluate

More information

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES Midterm Examination Douglas Wilhelm Harder 1.5 hrs, 2005/02/17 11 pages Name (last, first):

More information

This UML diagram was made using the Eclipse plugin: ObjectAid UML available at: To upgrade your Eclipse IDE do this:

This UML diagram was made using the Eclipse plugin: ObjectAid UML available at:  To upgrade your Eclipse IDE do this: Part 2. One-To-Many Relationship. Inheritance This UML diagram was made using the Eclipse plugin: ObjectAid UML available at: www.objectaid.com. To upgrade your Eclipse IDE do this: (Main Menu) Help >

More information

Introduction to Linked Data Structures

Introduction to Linked Data Structures Introduction to Linked Data Structures A linked data structure consists of capsules of data known as nodes that are connected via links Links can be viewed as arrows and thought of as one way passages

More information

Solutions to a few of the review problems:

Solutions to a few of the review problems: Solutions to a few of the review problems: Problem 1 The interface Deque can have array based and linked implementations. Partial versions of implementation classes follow. Supply implementations for the

More information

1. Introduction. Lecture Content

1. Introduction. Lecture Content Lecture 6 Queues 1 Lecture Content 1. Introduction 2. Queue Implementation Using Array 3. Queue Implementation Using Singly Linked List 4. Priority Queue 5. Applications of Queue 2 1. Introduction A queue

More information

CSCD 326 Data Structures I Queues

CSCD 326 Data Structures I Queues CSCD 326 Data Structures I Queues 1 Linked List Queue Implementation Diagram Front Back A B C D 0 6 public interface QueueInterface { Queue Interface public boolean isempty(); // Determines whether

More information

CS S-20 Linked Lists III 1. We can then use the next pointer of the previous node to do removal (example on board)

CS S-20 Linked Lists III 1. We can then use the next pointer of the previous node to do removal (example on board) CS112-2012S-20 Linked Lists III 1 20-0: Linked List ious Practical Example: removeat(int index) remove( o) 20-1: removeat First need to get to node before the one we want to remove We can then use the

More information

Implementing Dynamic Data Structures

Implementing Dynamic Data Structures Chapter 16 Implementing Dynamic Data Structures Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN:

More information

CSCD 326 Data Structures I Stacks

CSCD 326 Data Structures I Stacks CSCD 326 Data Structures I Stacks 1 Stack Interface public interface StackInterface { public boolean isempty(); // Determines whether the stack is empty. // Precondition: None. // Postcondition: Returns

More information

Suppose that we have linked list of integers where each node is represented as: // An item in the list.

Suppose that we have linked list of integers where each node is represented as: // An item in the list. Linked List Suppose that we have linked list of integers where each node is represented as: class ListNode { int item; // An item in the list. ListNode next; // Pointer to next item in the list. This node

More information

Linked List Practice Questions

Linked List Practice Questions Linked List Practice Questions 1. The following function reverse() is supposed to reverse a singly linked list. There is one line missing at the end of the function. /* head_ref is a double pointer which

More information

King Saud University College of Computer and Information Systems Department of Computer Science CSC 113: Java Programming-II, Spring 2016

King Saud University College of Computer and Information Systems Department of Computer Science CSC 113: Java Programming-II, Spring 2016 Create the classes along with the functionality given in the following UML Diagram. To understand the problem, please refer to the description given after the diagram. Node +Node(e:Employee) +getdata():employee

More information

(Constructor) public A (int n){ for (int i = 0; i < n; i++) { new A(i); } System.out.println("*"); }

(Constructor) public A (int n){ for (int i = 0; i < n; i++) { new A(i); } System.out.println(*); } !!#!#"! (Constructor) A public A (int n){ for (int i = 0; i < n; i++) { new A(i); System.out.println("*"); % 1. new A(0); 2. new A(1); 3. new A(2); 4. new A(3); & ) n 5. A a = new A(n);! '#" +"()* " %floating

More information

: Advanced Programming Final Exam Summer 2008 June 27, 2008

: Advanced Programming Final Exam Summer 2008 June 27, 2008 15-111 : Advanced Programming Final Exam Summer 2008 June 27, 2008 Name: Andrew ID: Answer the questions in the space provided following each question. We must be able to clearly understand your answer.

More information

ECM1406. Answer Sheet Lists

ECM1406. Answer Sheet Lists ECM1406 Answer Sheet Lists These questions are based on those found in Chapters 3 and 4 of the core text Data Structures Using Java by Malik and Nair. The source code for the ArrayListClass, UnorderedArrayList,

More information

Java Linked List Interview Questions

Java Linked List Interview Questions Java Linked List Interview Questions codespaghetti.com/linked-list-interview/ Linked List Java LinkedList Interview Questions, Programs and Algorithms. Table of Contents: CHAPTER 1: Top 5 Java Linked List

More information

Exceptions Questions https://www.journaldev.com/2167/java-exception-interview-questionsand-answers https://www.baeldung.com/java-exceptions-interview-questions https://javaconceptoftheday.com/java-exception-handling-interviewquestions-and-answers/

More information

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines

More information

DM537 Object-Oriented Programming. Peter Schneider-Kamp.

DM537 Object-Oriented Programming. Peter Schneider-Kamp. DM537 Object-Oriented Programming Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm537/! RECURSION (REVISITED) 2 Recursion (Revisited) recursive function = a function that calls

More information

Introduction to Computer Science II CS S-20 Linked Lists III

Introduction to Computer Science II CS S-20 Linked Lists III Introduction to Computer Science II CS112-2012S-20 Linked Lists III David Galles Department of Computer Science University of San Francisco 20-0: Linked List Previous Practical Example: removeat(int index)

More information

APCS Unit 5 Exam. Assuming all four classes have a default constructor, which of the following statements would result in an error from the compiler?

APCS Unit 5 Exam. Assuming all four classes have a default constructor, which of the following statements would result in an error from the compiler? APCS Unit 5 Exam Name 1. Suppose we had a superclass called Fruit. The subclasses of this superclass are Apple, Orange, and Banana. Consider the following reference variable declarations. Fruit f; Banana

More information

CSC 172 Data Structures and Algorithms. Lecture #9 Spring 2018

CSC 172 Data Structures and Algorithms. Lecture #9 Spring 2018 CSC 172 Data Structures and Algorithms Lecture #9 Spring 2018 SINGLY LINKED LIST 3.1.3 Linked lists We will consider these for Singly linked lists Doubly linked lists Basic Singly Linked List class Node

More information

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018 Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment

More information

Lists. ordered lists unordered lists indexed lists 9-3

Lists. ordered lists unordered lists indexed lists 9-3 The List ADT Objectives Examine list processing and various ordering techniques Define a list abstract data type Examine various list implementations Compare list implementations 9-2 Lists A list is a

More information

Linked Lists. A dynamically resizable efficient list implementation. Tip For Success: Reminder

Linked Lists. A dynamically resizable efficient list implementation. Tip For Success: Reminder Linked Lists A dynamically resizable efficient list implementation Tip For Success: Reminder Look through the examples and notes before class. This is especially important for this section because the

More information

Inheritance (Part 5) Odds and ends

Inheritance (Part 5) Odds and ends Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there

More information

IMPLEMENTING BINARY TREES

IMPLEMENTING BINARY TREES IMPLEMENTING BINARY TREES Chapter 6 A Binary Tree BinaryTree a = new BinaryTree(); a A B C D E F 1 A Binary Tree BinaryTree a = new BinaryTree(); a A B C D E F A Binary

More information

Name:... ID:... class A { public A() { System.out.println( "The default constructor of A is invoked"); } }

Name:... ID:... class A { public A() { System.out.println( The default constructor of A is invoked); } } KSU/CCIS/CS CSC 113 Final exam - Fall 12-13 Time allowed: 3:00 Name:... ID:... EXECRICE 1 (15 marks) 1.1 Write the output of the following program. Output (6 Marks): class A public A() System.out.println(

More information

Linked List. ape hen dog cat fox. tail. head. count 5

Linked List. ape hen dog cat fox. tail. head. count 5 Linked Lists Linked List L tail head count 5 ape hen dog cat fox Collection of nodes with a linear ordering Has pointers to the beginning and end nodes Each node points to the next node Final node points

More information

CSE1030 Lecture #18. CSE1030 Introduction to Computer Science II. Linked List Terminology

CSE1030 Lecture #18. CSE1030 Introduction to Computer Science II. Linked List Terminology CSE1030 Introduction to Computer Science II Lecture #18 Linked Lists Coding Examples CSE1030 Lecture #18 Review Iterating Inserting Deleting Extensions to Singly Linked-Lists Doubly-Linked-Lists We're

More information

COE318 Lecture Notes Week 8 (Oct 24, 2011)

COE318 Lecture Notes Week 8 (Oct 24, 2011) COE318 Software Systems Lecture Notes: Week 8 1 of 17 COE318 Lecture Notes Week 8 (Oct 24, 2011) Topics == vs..equals(...): A first look Casting Inheritance, interfaces, etc Introduction to Juni (unit

More information

Implementing Lists, Stacks, Queues, and Priority Queues

Implementing Lists, Stacks, Queues, and Priority Queues Implementing Lists, Stacks, Queues, and Priority Queues CSE260, Computer Science B: Honors Stony Brook University http://www.cs.stonybrook.edu/~cse260 1 Objectives To design common features of lists in

More information

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012)

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012) COE318 Lecture Notes: Week 9 1 of 14 COE318 Lecture Notes Week 9 (Week of Oct 29, 2012) Topics The final keyword Inheritance and Polymorphism The final keyword Zoo: Version 1 This simple version models

More information

Abstract Data Types - Lists Arrays implementa4on Linked- lists implementa4on

Abstract Data Types - Lists Arrays implementa4on Linked- lists implementa4on Abstract Data Types - Lists Arrays implementa4on Linked- lists implementa4on Lecture 16 Jérôme Waldispühl School of Computer Science McGill University Slides by Mathieu BlancheIe Recap from last lecture

More information

2018/2/5 话费券企业客户接入文档 语雀

2018/2/5 话费券企业客户接入文档 语雀 1 2 2 1 2 1 1 138999999999 2 1 2 https:lark.alipay.com/kaidi.hwf/hsz6gg/ppesyh#2.4-%e4%bc%81%e4%b8%9a%e5%ae%a2%e6%88%b7%e6%8e%a5%e6%94%b6%e5%85%85%e5 1/8 2 1 3 static IAcsClient client = null; public static

More information

Ryerson University Department of Electrical & Computer Engineering COE618 Midterm Examination February 26, 2013

Ryerson University Department of Electrical & Computer Engineering COE618 Midterm Examination February 26, 2013 Ryerson University Department of Electrical & Computer Engineering COE618 Midterm Examination February 26, 2013 Name: Student # : Time: 90 minutes Instructions This exam contains 6 questions. Please check

More information

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011 Stacks (5.1) CSE 2011 Winter 2011 26 January 2011 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error

More information

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice Name Section Number CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice All Sections Bob Wilson OPEN BOOK / OPEN NOTES: You will have all 90 minutes until the start of the next class period.

More information

Laboratorio di Algoritmi e Strutture Dati

Laboratorio di Algoritmi e Strutture Dati Laboratorio di Algoritmi e Strutture Dati Guido Fiorino guido.fiorino@unimib.it aa 2013-2014 2 Linked lists (of int) We focus on linked lists for integers; let us start with a class that defines a node

More information

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Java We will be programming in Java in this course. Partly because it is a reasonable language, and partly because you

More information

Introduction To Data Structures

Introduction To Data Structures Introduction To Data Structures This section introduces the concept of a data structure as well as providing the details of a specific example: a list. Tip For Success: Reminder Look through the examples

More information

COMPSCI 105 S Principles of Computer Science. 17 Linked List(1)

COMPSCI 105 S Principles of Computer Science. 17 Linked List(1) COMPSCI 105 S1 2017 Principles of Computer Science 17 Linked List(1) Agenda Agenda & Readings Introduction The Node class The UnorderedList ADT Comparing Implementations Reference: Textbook: Problem Solving

More information

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader Prelim 1 Solutions CS 2110, March 10, 2015, 5:30 PM 1 2 3 4 5 Total Question True False Short Answer Recursion Object Oriented Loop Invariants Max 20 15 20 25 20 100 Score Grader The exam is closed book

More information

CS18000: Problem Solving and Object-Oriented Programming

CS18000: Problem Solving and Object-Oriented Programming CS18000: Problem Solving and Object-Oriented Programming Recursion 28 March 2011 Prof. Chris Clifton Recursion Idea: break a problem down into small, similar sub-problems Write a method to solve first

More information

CS350: Data Structures Linked Lists

CS350: Data Structures Linked Lists Linked Lists James Moscola Department of Physical Sciences York College of Pennsylvania James Moscola Linked Lists Come in a variety of different forms - singly linked lists - doubly linked lists - circular

More information

Generics in Java. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG

Generics in Java. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Generics in Java EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Motivating Example: A Book of Objects 1 class Book { 2 String[] names; 3 Object[] records; 4 /* add a name-record

More information

Motivating Example: Observations (1) Generics in Java. Motivating Example: A Book of Objects. Motivating Example: Observations (2)

Motivating Example: Observations (1) Generics in Java. Motivating Example: A Book of Objects. Motivating Example: Observations (2) Motivating Example: Observations (1) Generics in Java EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG In the Book class: By declaring the attribute Object[] records We meant that

More information

CMPSCI 187 Midterm 1 (Feb 17, 2016)

CMPSCI 187 Midterm 1 (Feb 17, 2016) CMPSCI 187 Midterm 1 (Feb 17, 2016) Instructions: This is a closed book, closed notes exam. You have 120 minutes to complete the exam. The exam has 10 pages printed on double sides. Be sure to check both

More information

Linked Lists. A dynamically resizable, efficient implementation of a list. Tip For Success: Reminder

Linked Lists. A dynamically resizable, efficient implementation of a list. Tip For Success: Reminder Linked Lists A dynamically resizable, efficient implementation of a list Tip For Success: Reminder Look through the examples and notes before class. This is especially important for this section because

More information

Arun chakravarthy Alagar samy. Technical Skill. Java Code Challenge - Basic Java

Arun chakravarthy Alagar samy. Technical Skill. Java Code Challenge - Basic Java Arun chakravarthy Alagar samy E-MAIL arunchakkravarthy@gmail.com DATE OF LAST ACTIVITY 2017-11-27 TEST Java Code Challenge - Basic LANGUAGES USED Java Technical Skill CANDIDATE RESULT SKILL THRESHOLD Strongly

More information

Lists using LinkedList

Lists using LinkedList Lists using LinkedList 1 LinkedList Apart from arrays and array lists, Java provides another class for handling lists, namely LinkedList. An instance of LinkedList is called a linked list. The constructors

More information

1.00 Introduction to Computers and Engineering Problem Solving. Final Examination - May 19, 2004

1.00 Introduction to Computers and Engineering Problem Solving. Final Examination - May 19, 2004 1.00 Introduction to Computers and Engineering Problem Solving Final Examination - May 19, 2004 Name: E-mail Address: TA: Section: You have 3 hours to complete this exam. For coding questions, you do not

More information

Linked Lists. Chapter 12.3 in Savitch

Linked Lists. Chapter 12.3 in Savitch Linked Lists Chapter 12.3 in Savitch Preliminaries n Arrays are not always the optimal data structure: q An array has fixed size needs to be copied to expand its capacity q Adding in the middle of an array

More information

Introducing Generics

Introducing Generics Generics Introducing Generics Generics allow reference types (classes, interfaces, and array types) and methods to be parameterized with type information. An abstract data type (ADT) defines both the types

More information

CIS265 Homework7 A (partial) solution showing creation/traversal of an expression-tree made from a a valid arithmetical expression

CIS265 Homework7 A (partial) solution showing creation/traversal of an expression-tree made from a a valid arithmetical expression CIS265 Homework7 A (partial) solution showing creation/traversal of an expression-tree made from a a valid arithmetical expression Driver package csu.matos; import java.util.stack; import java.util.stringtokenizer;

More information

Linked Lists. Chapter 4

Linked Lists. Chapter 4 Linked Lists Chapter 4 1 Linked List : Definition Linked List: A collection of data items of the same type that are stored in separate objects referred to as "nodes". Each node contains, in addition to

More information

Full file at Chapter 2 - Inheritance and Exception Handling

Full file at   Chapter 2 - Inheritance and Exception Handling Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a

More information

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can

More information

Notes on access restrictions

Notes on access restrictions Notes on access restrictions A source code file MyClass.java is a compilation unit and can contain at most one public class. Furthermore, if there is a public class in that file, it must be called MyClass.

More information

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator מבוא למדעי המחשב 2017 תרגול 8 רשימה משורשרת כללית, Comparator בתרגול היום. LinkedList בניית ההכללה מ- LinkIntList תרגול המבנה ושימושיו ממשקים: Comparator Sorted Linked List ל- LinkedList ע"י שימוש ב- Comparator

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 07: Linked Lists MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Linked Lists 2 Introduction Linked List Abstract Data Type SinglyLinkedList ArrayList Keep in Mind Introduction:

More information

Lab 11. A sample of the class is:

Lab 11. A sample of the class is: Lab 11 Lesson 11-2: Exercise 1 Exercise 2 A sample of the class is: public class List // Methods public void store(int item) values[length] = item; length++; public void printlist() // Post: If the list

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 07: Linked Lists and Iterators MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Linked Lists 2 Introduction Linked List Abstract Data Type General Implementation of the ListADT

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

Java Generics -- an introduction. Based on https://docs.oracle.com/javase/tutorial/java/generics/why.html

Java Generics -- an introduction. Based on https://docs.oracle.com/javase/tutorial/java/generics/why.html Java Generics -- an introduction Based on https://docs.oracle.com/javase/tutorial/java/generics/why.html Generics vs. Templates Templates in C++ are compiled into unique code based on the types passed

More information

Introduction to Computer Science II CS S-20 Linked Lists IV

Introduction to Computer Science II CS S-20 Linked Lists IV Introduction to Computer Science II CS112-2012S-20 Linked Lists IV David Galles Department of Computer Science University of San Francisco 20-0: Doubly Linked List Deleting from (and inserting into!) a

More information

Linked Lists. References and objects

Linked Lists. References and objects Linked Lists slides created by Marty Stepp http://www.cs.washington.edu/143/ Modified by Sarah Heckman Reading: RS Chapter 16 References and objects In Java, objects and arrays use reference semantics.

More information

Course Project Hospital Information Management

Course Project Hospital Information Management Course Project Hospital Information Management Data Structures and Algorithms I [CSIS-3103-002] Team 3 Thomas Sadowski (Z00300233) William Gray (Z00303491) Keith Lopez (Z00285342) Shaifur Rahmans (Z00249132)

More information

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide Topics for Exam 2: Queens College, CUNY Department of Computer Science CS 212 Object-Oriented Programming in Java Practice Exam 2 CS 212 Exam 2 Study Guide Linked Lists define a list node define a singly-linked

More information

Chapter 11: Collections and Maps

Chapter 11: Collections and Maps Chapter 11: Collections and Maps Implementing the equals(), hashcode() and compareto() methods A Programmer's Guide to Java Certification (Second Edition) Khalid A. Mughal and Rolf W. Rasmussen Addison-Wesley,

More information

Java Classes, Inheritance, and Interfaces

Java Classes, Inheritance, and Interfaces Java Classes, Inheritance, and Interfaces Introduction Classes are a foundational element in Java. Everything in Java is contained in a class. Classes are used to create Objects which contain the functionality

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

CSE 2123: Collections: Priority Queues. Jeremy Morris

CSE 2123: Collections: Priority Queues. Jeremy Morris CSE 2123: Collections: Priority Queues Jeremy Morris 1 Collections Priority Queue Recall: A queue is a specific type of collection Keeps elements in a particular order We ve seen two examples FIFO queues

More information

Abstract Data Types - Lists Arrays implementation Linked-lists implementation

Abstract Data Types - Lists Arrays implementation Linked-lists implementation Abstract Data Types - Lists Arrays implementation Linked-lists implementation Lecture 17 Jérôme Waldispühl School of Computer Science McGill University From slides by Mathieu Blanchette Abstract data types

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8 Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg

More information

Informatik II Tutorial 6. Subho Shankar Basu

Informatik II Tutorial 6. Subho Shankar Basu Informatik II Tutorial 6 Subho Shankar Basu subho.basu@inf.ethz.ch 06.04.2017 Overview Debriefing Exercise 5 Briefing Exercise 6 2 U05 Some Hints Variables & Methods beginwithlowercase, areverydescriptiveand

More information

CSC 321: Data Structures. Fall 2016

CSC 321: Data Structures. Fall 2016 CSC 321: Data Structures Fall 2016 Trees & recursion trees, tree recursion BinaryTree class BST property BinarySearchTree class: override add, contains search efficiency 1 Trees a tree is a nonlinear data

More information

Exercise 12 Initialization December 16, 2016

Exercise 12 Initialization December 16, 2016 Concepts of Object-Oriented Programming AS 2016 Exercise 12 Initialization December 16, 2016 Task 1 Consider a Java class Vector, representing a 2 dimensional vector: public class Vector { public Number!

More information

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi Stack and Queue How do we implement a Queue using Array? : A collection of nodes with linear ordering defined on them. Each node holds an element and points to the next node in the order. The first node

More information

Topic 11 Linked Lists

Topic 11 Linked Lists Topic 11 "All the kids who did great in high school writing pong games in BASIC for their Apple II would get to college, take CompSci 101, a data structures course, and when they hit the pointers business

More information

CMPSCI 187: Programming With Data Structures. Lecture #23: Linked Lists David Mix Barrington 31 October 2012

CMPSCI 187: Programming With Data Structures. Lecture #23: Linked Lists David Mix Barrington 31 October 2012 CMPSCI 187: Programming With Data Structures Lecture #23: Linked Lists David Mix Barrington 31 October 2012 Linked Lists Implementing Lists With References The find Method The RefUnsortedList Class Methods

More information

Object Oriented Design. Object-Oriented Design. Inheritance & Polymorphism. Class Hierarchy. Goals Robustness Adaptability Flexible code reuse

Object Oriented Design. Object-Oriented Design. Inheritance & Polymorphism. Class Hierarchy. Goals Robustness Adaptability Flexible code reuse Object-Oriented Design Object Oriented Design Goals Robustness Adaptability Flexible code reuse Principles Abstraction Encapsulation Modularity March 2005 Object Oriented Design 1 March 2005 Object Oriented

More information

COE318 Lecture Notes Week 10 (Nov 7, 2011)

COE318 Lecture Notes Week 10 (Nov 7, 2011) COE318 Software Systems Lecture Notes: Week 10 1 of 5 COE318 Lecture Notes Week 10 (Nov 7, 2011) Topics More about exceptions References Head First Java: Chapter 11 (Risky Behavior) The Java Tutorial:

More information

Informatik II (D-ITET) Tutorial 6. TA: Anwar Hithnawi, Distributed Systems Group, ETH Zürich

Informatik II (D-ITET) Tutorial 6. TA: Anwar Hithnawi,   Distributed Systems Group, ETH Zürich Informatik II (D-ITET) Tutorial 6 TA: Anwar Hithnawi, E-mail: hithnawi@inf.ethz.ch Distributed Systems Group, ETH Zürich Outlook Exercise 5: Solution discussion More Java insights (Inheritance and Interfaces)

More information

Introduction to Computer Science II (CSI 1101) Midterm Examination

Introduction to Computer Science II (CSI 1101) Midterm Examination Identification Student name: Introduction to Computer Science II (CSI 1101) Midterm Examination Instructor: Marcel Turcotte February 2003, duration: 2 hours Student number: Section: Instructions 1. This

More information

CS 1316 Exam 2 Summer 2009

CS 1316 Exam 2 Summer 2009 1 / 8 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 2 Summer 2009 Section/Problem

More information