300 likes | 316 Views
CSC 364 001 Data Structures and Algorithms Lee Weiner 572-6025 weinerl@nku.edu. Student - lastName : String - firstName : String - state : String - major : String + createStudent() + getFirstName() : String + setFirstName() : void + getLastName() : String + setLastName() : void
E N D
CSC 364 001 Data Structures and Algorithms Lee Weiner 572-6025 weinerl@nku.edu
Student - lastName : String - firstName : String - state : String - major : String + createStudent() + getFirstName() : String + setFirstName() : void + getLastName() : String + setLastName() : void + getState() : String + setState() : void + getMajor() : String + setMajor() : void + getRate() : int - isStateValid(): boolean - isMajorValid() : boolean Student - lastName : String - firstName : String - state : String - major : String + createStudent() + getFirstName() + setFirstName() + getLastName() + setLastName() + getState() + setState() + getMajor() + setMajor() + getRate() - isStateValid() - isMajorValid() Student - lastName : String - firstName : String - state : String - major : String + createStudent() + getFirstName() + setFirstName() + getLastName() + setLastName() + getState() + setState() + getMajor() + setMajor() + getRate() - isStateValid() - isMajorValid()
Lee Dan Joe Bob aaaa cccc ffff null abcd abcd aaaa cccc ffff head
Node - data : Object - link : Node + createNode() + getData() : Object + setData() : void + getLink() : Node + setLink() : void
Lee Dan Joe Bob Barb aaaa cccc ffff null cccc abcd abcd aaaa cccc ffff xxxx head link = new Node( data, link );
Lee Dan Joe Bob Barb aaaa xxxx ffff null cccc abcd abcd aaaa cccc ffff xxxx head
Lee Dan Joe Bob aaaa cccc ffff null abcd abcd aaaa cccc ffff head link = link.link;
Lee Dan Joe Bob aaaa ffff ffff null abcd abcd aaaa cccc ffff head
Node - data : Object - link : Node + createNode() + getData() : Object + setData() : void + getLink() : Node + setLink() : void + addNodeAfter() : void + removeNodeAfter() : void
Node current = head; while( current != null ) { System.out.println( current.getData() ); current = current.getLink(); } Traversing a Linked List
if( head == null ) head = new Node( data, null ); else { Node current = head; while( current.getLink() != null ) current = current.getLink(); current.addNodeAfter( data ); } Adding a Node to the End of the List
LinkedList - head : Node + createLinkedList() + add(Object) + add(Object, int) + clear() + get(int) : Node + isEmpty() : boolean + size() : int + find(Object) : int + remove(Object) + remove(int) - getReference(int) : Node
Node - data : Object - link : Node + createNode() + getData() + setData() + getLink() + setLink() + addNodeAfter() + removeNodeAfter() LinkedList - head : Node + createLinkedList() + add(Object) + add(Object, int) + clear() + get(int) : Node + isEmpty() : boolean + size() : int + find(Object) : int + remove(Object) + remove(int) - getReference(int) : Node 0..* 1 UML “Has A” Relationship
Employee - home : HomeAddress - job : JobInfo - insurance : Insurance - ssn : String - lastName : String - firstName : String + createEmployee() + getSSN() : String + setSSN() + getFirstName() : String + setFirstName() + getLastName() : String + setLastName() HomeAddress - street : String - addr2 : String - city : String - state : String - zip : String + getStreet() : String + setStreet() + getAddr2() : String + setString() . . . JobInfo - jobCode : String - title : String - salary : String - location : JobAddress - startDate : Date + getJobCode() : String + setJobCode() + getTitle() : String + setTitle() . . . 1 1 1 0..* Another Use of "Has A"
Stack - stack : LinkedList + createStack() + push( Object ) + pop() : Object + peek() : Object + isEmpty() : boolean
Queue - queue : LinkedList + createQueue() + enqueue( Object ) + dequeue() : Object + size() : int + isEmpty() : boolean
1 2 3 3 4 Priority Queue
1 2 2 3 4 Priority Queue
1 2 3 3 4 Priority Queue
1 2 1 3 4 Priority Queue
1 2 3 4 Priority Queue
1 2 1 3 4 Priority Queue
1 2 3 4 Priority Queue
1 2 3 4 Priority Queue
1 2 3 4 Priority Queue
1 2 3 4 Priority Queue
enqueue(Object, int) - Add a node in the priority specified by the int • dequeue() - Loop through the priorities, dequeue a node from the highest priority that has one • size() - Loop through all priorities, summing and returning number of nodes. • isEmpty() - If all priorities are empty, return true 4 Queue Methods for Priority Queue
Stack - stack : LinkedList + createStack() + push( Object ) + pop() : Object + peek() : Object + isEmpty() : boolean 1 1 LinkedList - head : Node + createLinkedList() + add(Object) + add(Object, int) + clear() + get(int) : Node + isEmpty() : boolean + size() : int + find(Object) : int + remove(Object) + remove(int) - getReference(int) : Node