Marcus Biel, Software Craftsman

Slides:



Advertisements
Similar presentations
Chapter 24 Lists, Stacks, and Queues
Advertisements

AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
Chapter 6 The Collections API. Simple Container/ Iterator Simple Container Shape [] v = new Shape[10]; Simple Iterator For( int i=0 ; i< v.length ; i++)
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L11 (Chapter 20) Lists, Stacks,
CSSE221: Software Dev. Honors Day 13 Announcements Announcements Contractions throughout the night… Contractions throughout the night… Late day assignments.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 26 Implementing Lists, Stacks,
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
1 Lecture 26 Abstract Data Types – IV Overview  The List ADT  Implementing Stacks as Linked List  Linked List Implementation of Queues .  Preview:
Stacks, Queues, and Deques
Stacks, Queues, and Deques
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
LinkedList Many slides from Horstmann modified by Dr V.
Data structures Abstract data types Java classes for Data structures and ADTs.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
Queue FIFO (First In First Out) Java Doc peek, element offer poll, add
Week 3 - Friday.  What did we talk about last time?  Stacks  Array implementation of a stack.
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Generics and Collections Course Lecture Slides 19 th July 2010 “Never.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
LECTURE 27: DEQUES CSC 212 – Data Structures. Roses are red and violets are blue Implement push, pop, & top And you’re a Stack too! Stack & ADT Memory.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
List Interface and Linked List Mrs. Furman March 25, 2010.
CS-2851 Dr. Mark L. Hornick 1 Stacks and Queues Behavior vs. Structure.
 2015, Marcus Biel, Linked List Data Structure Marcus Biel, Software Craftsman
 2016, Marcus Biel, ArrayList Marcus Biel, Software Craftsman
Week 15 – Monday.  What did we talk about last time?  Tries.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
1 Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues Jung Soo (Sue) Lim Cal State LA.
CSCI 62 Data Structures Dr. Joshua Stough September 23, 2008.
Prefix notation in action
Elementary Data Structures
Week 4 - Monday CS221.
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Queue FIFO (First In First Out) Java Doc peek, element poll, remove
12 Collections Software Solutions Lewis & Loftus java 5TH EDITION
Double-Ended Queues Chapter 5.
Csc 2720 Data structure Instructor: Zhuojun Duan
Chapter 12: Data Structures
Priority Queue.
Chapter 17 Object-Oriented Data Structures
Top Ten Words that Almost Rhyme with “Peas”
Introduction to Data Structures
structures and their relationships." - Linus Torvalds
Queues, Deques and Priority Queues
Linked Lists.
THURSDAY, OCTOBER 17 IN LAB
Queues, Deques and Priority Queues
Stacks, Queues, and Deques
Stacks, Queues, and Deques
Programming II (CS300) Chapter 07: Linked Lists and Iterators
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Collections Framework
Copyright © Aiman Hanna All rights reserved
More Data Structures (Part 1)
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks, Queues, and Deques
TCSS 143, Autumn 2004 Lecture Notes
structures and their relationships." - Linus Torvalds
Queues.
Queues, Deques, and Priority Queues
Presentation transcript:

Marcus Biel, Software Craftsman http://www.marcus-biel.com java.util.LinkedList Explore the Linked List data structure further, specifically focusing on the java.util.LinkedList class for more visit- Marcus Biel, Software Craftsman http://www.marcus-biel.com

Doubly Linked List 23 3 17 9 42 In the previous ( http://www.slideshare.net/MarcusBiel/linked-listdata-structure ) episode I introduced you to the Linked List data structure. In the previous episode I introduced you to the Linked List data structure.

Doubly Linked List 23 3 17 9 42 As the name implies, the Java class LinkedList is called LinkedList because internally it is based on a Doubly Linked List.  As the name implies, the Java class LinkedList is called LinkedList because internallyit is based on a Doubly Linked List. 

Concept vs. Implementation So what is the difference between the LinkedList data structure and the class java.util.LinkedList? So what is the difference between the LinkedList data structure and the class java.util.LinkedList?

Concept vs. Implementation As an analogy, think of the abstract concept of a car and a concrete car. As an analogy, think of the abstract concept of a car and a concrete car.

Concept vs. Implementation The Linked List data structure is an abstract concept, independent of any specific programming language. The Linked List data structure is an abstract concept, independent of any specific programming language.

Concept vs. Implementation The LinkedList Java class is a concrete implementation of this abstract concept.  The LinkedList Java class is a concrete implementation of this abstract concept. 

java.util.LinkedList So in this tutorial, I will focus on one specific So in this episode I will focus on one specific Linked List implementation, the java.util.LinkedList class. Implements Extends So in this tutorial, I will focus on one specific Linked List implementation, the java.util.LinkedList class.

java.util.LinkedList Among other interfaces, <<interface>> List Among other interfaces, LinkedList implements the java.util.List interface. LinkedList Implements Extends Among other interfaces, LinkedList implements the java.util.List interface.

java.util.LinkedList You can have duplicate elements in a List and <<interface>> List You can have duplicate elements in a List and you can go from element to element in the same order as the elements were inserted. LinkedList Implements Extends You can have duplicate elements in a List and you can go from element to element in the same order as the elements were inserted.

ArrayList vs. LinkedList <<interface>> List In a previous tutorial (http://www.marcus-biel.com/arraylist/), I introduced you to the java.util.ArrayList class. ArrayList LinkedList Implements Extends In a previous tutorial, I introduced you to the java.util.ArrayList class.

ArrayList vs. LinkedList <<interface>> List As you can see, both classes implement the List interface which makes them somewhat similar. So what’s the difference between ArrayList and LinkedList? ArrayList LinkedList Implements Extends As you can see, both classes implement the List interface, which makes them somewhat similar. So what’s the difference between ArrayList and LinkedList?

ArrayList vs. LinkedList 1 2 3 4 23 17 9 42 First of all, ArrayList ( http://www.marcus-biel.com/arraylist/ ) is based on an Array data structure, First of all, ArrayList is based on an Array data structure,

ArrayList vs. LinkedList 1 2 3 4 23 17 9 42 while LinkedList is based on a Doubly Linked List data structure. 23 3 17 9 42 while LinkedList is based on a Doubly Linked List data structure.

ArrayList vs. LinkedList 1 2 3 4 23 17 9 42 Compared to an ArrayList, the Doubly Liked List data structure of the LinkedList class allows more efficient insertion and removal of elements at any position within the List. 23 3 17 9 42 Compared to an ArrayList, the Doubly Liked List data structure of the LinkedList class allows more efficient insertion and removal of elements at any position within the List.

ArrayList vs. LinkedList 23 3 17 9 42 Therefore, as an implementation of the List interface prefer LinkedList over ArrayList if your main use is to add or remove elements at random positions in the List. Therefore, as an implementation of the List interface prefer LinkedList over ArrayList if your main use is to add or remove elements at random positions in the List.

ArrayList vs. LinkedList 1 2 3 4 23 17 9 42 Otherwise, ArrayList might be a better choice, because storing elements in an array consumes less memory and generally gives faster access times. Otherwise, ArrayList might be a better choice, because storing elements in an array consumes less memory and generally gives faster access times.

ArrayList vs. LinkedList <<interface>> Collection Besides the different data structures of ArrayList and LinkedList, LinkedList also implements the Queue and the Deque interfaces which gives it some additional functionality over ArrayList. <<interface>> Queue Implements Extends <<interface>> List <<interface>> Deque ArrayList LinkedList Besides the different data structures of ArrayList and LinkedList LinkedList also implements the Queue and the Deque interfaces which gives it some additional functionality over ArrayList.

ArrayList vs. LinkedList <<interface>> Collection In conclusion, there is no overall winner between ArrayList and LinkedList. Your specific requirements will determine which class to use. <<interface>> Queue Implements Extends <<interface>> List <<interface>> Deque ArrayList LinkedList In conclusion, there is no overall winner between ArrayList and LinkedList. Your specific requirements will determine which class to use.

LinkedList Let’s put ArrayList aside for now and <<interface>> Collection Let’s put ArrayList aside for now and have an in-depth look at the LinkedList implementation. <<interface>> Queue Implements Extends <<interface>> List <<interface>> Deque LinkedList Let’s put ArrayList aside for now and have an in-depth look at the LinkedList implementation.

Here is a simplified code excerpt from the java.util.LinkedList class. package java.util; public class LinkedList<E> implements List<E>,Deque<E>{ private Node<E> first; private Node<E> last; public E get(int index) {…} public boolean add(E e) {…} public E remove(int index) {…} […] } Here is a simplified code excerpt from the java.util.LinkedList class. Here is a simplified code excerpt from the java.util.LinkedList class.

LinkedList I don’t expect you to fully grasp every detail of the code, package java.util; public class LinkedList<E> implements List<E>,Deque<E>{ private Node<E> first; private Node<E> last; public E get(int index) {…} public boolean add(E e) {…} public E remove(int index) {…} […] } I don’t expect you to fully grasp every detail of the code, I just want to show you that LinkedList is a normal Java class which anyone could have written, given enough time and knowledge. I don’t expect you to fully grasp every detail of the code, I just want to show you that LinkedList is a normal Java class which anyone could have written, given enough time and knowledge.

LinkedList The real source code is available online. package java.util; public class LinkedList<E> implements List<E>,Deque<E>{ private Node<E> first; private Node<E> last; public E get(int index) {…} public boolean add(E e) {…} public E remove(int index) {…} […] } The real source code is available online. After watching this episode, I recommend that you take a look at it for yourself. The real source code is available online. After finishing this presentation, I recommend that you take a look at it for yourself.

LinkedList So, as you can see, LinkedList implements the package java.util; public class LinkedList<E> implements List<E>,Deque<E>{ private Node<E> first; private Node<E> last; public E get(int index) {…} public boolean add(E e) {…} public E remove(int index) {…} […] } Okay. So, as you can see, LinkedList implements the List, Queue and Deque interfaces, as Deque extends the Queue interface. So, as you can see, LinkedList implements the List, Queue and Deque interfaces, as Deque extends the Queue interface.

LinkedList Next you can see that the LinkedList class package java.util; public class LinkedList<E> implements List<E>,Deque<E>{ private Node<E> first; private Node<E> last; public E get(int index) {…} public boolean add(E e) {…} public E remove(int index) {…} […] } Next you can see that the LinkedList class has a reference to the first and the last elements of the list. Next you can see that the LinkedList class has a reference to the first and the last elements of the list.

LinkedList Finally, you can see that the class has functions like- package java.util; public class LinkedList<E> implements List<E>,Deque<E>{ private Node<E> first; private Node<E> last; public E get(int index) {…} public boolean add(E e) {…} public E remove(int index) {…} […] } Finally, you can see that the class has functions like get, add or remove - to access, insert or delete elements from the list. Finally, you can see that the class has functions like- get, add or remove to access, insert or delete elements from the list.

Doubly Linked List 23 3 17 9 42 As we just saw in the code, As we just saw in the code, the LinkedList class has a reference to the first and last elements of the list, shown as red arrows in this slide. As we just saw in the code, the LinkedList class has a reference to the first and last elements of the list, shown as red arrows in this slide.

Doubly Linked List 23 3 17 9 42 Every single element in a Doubly Linked List has a reference to its previous and next elements as well as a reference to an item, simplified as a number within a yellow box on this slide. Every single element in a Doubly Linked List has a reference to its previous and next elements as well as a reference to an item, simplified as a number within a yellow box on this slide.

Node Here you see a code excerpt of a Node. public class Node<E> { private E item; private Node<E> previous; private Node<E> next; public Node(E element, Node<E> previous, Node<E> next) { this.item = element; this.next = next; this.previous = previous; } } Here you see a code excerpt of a Node. It has private members for the item it holds, and for the previous and next Node in the list. Here you see a code excerpt of a Node. It has private members for the item it holds, and for the previous and next Node in the list.

LinkedList As a user of the Collections class LinkedList, package java.util; public class LinkedList<E> implements List<E>,Deque<E>{ private Node<E> first; private Node<E> last; public E get(int index) {…} public boolean add(E e) {…} public E remove(int index) {…} […] } As a user of the Collections class LinkedList, you never directly access the Nodes. As a user of the Collections class LinkedList, you never directly access the Nodes.

LinkedList Instead you use the public methods of the LinkedList class package java.util; public class LinkedList<E> implements List<E>,Deque<E>{ private Node<E> first; private Node<E> last; public E get(int index) {…} public boolean add(E e) {…} public E remove(int index) {…} […] } Instead you use the public methods of the LinkedList class that internally operate on the private Node members. Instead you use the public methods of the LinkedList class that internally operate on the private Node members.

java.util.List In my tutorial about ArrayList , <<interface>> List In the tutorial about ArrayList(http://www.marcus-biel.com/arraylist/). I introduced you to the methods of the List interface, so I won’t mention about those methods again. LinkedList In my tutorial about ArrayList , I introduced you to the methods of the List interface, so I won’t mention about those methods again.

java.util.Queue Instead, let’s go on and look at the methods of the <<interface>> Queue Instead, let’s go on and look at the methods of the Queue interface implemented by LinkedList. LinkedList Instead, let’s go on and look at the methods of the Queue interface implemented by LinkedList.

Operations on a Queue end (tail) front (head) 23 3 17 9 42 From a high level perspective, the Queue interface consists of three simple operations: end (tail) 23 3 17 9 42 front (head) From a high level perspective, the Queue interface consists of three simple operations:

add an element to the end of the Queue Operations on a Queue add element retrieve element retrieve and remove element add an element to the end of the Queue add an element to the end of the Queue

retrieve an element from the front of the Queue, Operations on a Queue add element retrieve element retrieve and remove element retrieve an element from the front of the Queue, without removing it. retrieve an element from the front of the Queue, without removing it.

but of course the operation returns a reference to the object Operations on a Queue add element retrieve element retrieve and remove element In the illustration the blue guy was copied, but of course the operation returns a reference to the object and does not copy it. but of course the operation returns a reference to the object and does not copy it.

Operations on a Queue add element retrieve element retrieve and remove element Okay. Finally you can retrieve and remove an element from the front of the Queue. Okay. Finally you can retrieve and remove an element from the front of the Queue.

Specific Events on a Queue In the lifetime of a Queue, there are special situations, In the lifetime of a Queue, there are special situations,

Specific Events on a Queue ? from an empty Queue like trying to remove an element… from an empty Queue

Specific Events on a Queue or trying to add an element to a Queue that has a limited capacity and is currently full. 23 3 17 9 42 39 25 11 16 20 34 or trying to add an element to a Queue that has a limited capacity and is currently full.

Specific Events on a Queue Depending on your specific implementation, this might be an expected situation and you need a method that returns null or false in this case. return special value throw Exception Depending on your specific implementation, this might be an expected situation and you need a method that returns null or false in this case.

Specific Events on a Queue Alternatively this might be an unexpected situation and you need a method that throws an Exception in this case. return special value throw Exception Alternatively this might be an unexpected situation and you need a method that throws an Exception in this case.

java.util.Queue Throws Exception Returns Special Value Add add Offer Retrieve element Peek Retrieve & Remove Remove Poll Therefore, the Queue interface offers each of its operations in two flavours - one method that will throw an Exception, and one that will return a special value in certain cases. Okay, let’s look at this in more detail. The Queue interface offers each of its operations in two flavours – one method that will throw an Exception, and one that will return a special value in certain cases. let’s look at this in more detail.

A Queue allows to add elements to the end of the Queue. boolean add(E e) boolean offer(E e) A Queue allows to add elements to the end of the Queue. A Queue allows to add elements to the end of the Queue.

Add elements boolean add(E e) boolean offer(E e) “add” will throw an Exception when the Queue is full, while “offer” will return false in this case. “add” will throw an Exception when the Queue is full, while “offer” will return false in this case.

Add elements boolean add(E e) boolean offer(E e) LinkedList, like most Queue implementations, has an unlimited capacity, so it will never be full. LinkedList, like most Queue implementations, has an unlimited capacity, so it will never be full.

Add elements boolean add(E e) boolean offer(E e) ArrayBlockingQueue on the other hand is a Queue implementation that has a limited capacity. ArrayBlockingQueue on the other hand is a Queue implementation that has a limited capacity.

Retrieve elements E element() E peek() Next, “element” and “peek” Next, “element” and “peek” allow you to retrieve an element from the front of the Queue, without removing it. Next, “element” and “peek” allow you to retrieve an element from the front of the Queue, without removing it.

Retrieve elements E element() E peek() If the Queue is empty, If the Queue is empty, the element function will throw an Exception, while peek() will return false. If the Queue is empty, the element function will throw an Exception, while peek() will return false.

Retrieve & remove elements E poll() Finally you can retrieve and remove an element from the front of the Queue. If the Queue is empty, remove will throw an Exception, while poll will return false. Finally you can retrieve and remove an element from the front of the Queue. If the Queue is empty, remove will throw an Exception, while poll will return false.

java.util.Deque <<interface>> Deque Okay, now we will look at some methods of the Deque interface, as implemented by LinkedList. LinkedList Okay, now we will look at some methods of the Deque interface, as implemented by LinkedList.

Deque is the short form of “Double Ended Queue” java.util.Deque <<interface>> Deque Deque is the short form of “Double Ended Queue” LinkedList Deque is the short form of “Double Ended Queue”

so it is a Queue that can be accessed from either end. java.util.Deque <<interface>> Deque so it is a Queue that can be accessed from either end. LinkedList so it is a Queue that can be accessed from either end.

java.util.Deque Just like a Queue, a Deque allows adding, retrieving throws Exception returns special value Add addFirst
addLast offerFirst
offerLast Retrieve getFirst
getLast peekFirst
peekFirst Retrieve & Remove removeFirst
removeLast pollFirst
pollLast Just like a Queue, a Deque allows adding, retrieving and - retrieving and removing - an element. Just like a Queue, a Deque allows adding, retrieving and - retrieving and removing - an element.

java.util.Deque But as it can be accessed from either end, throws Exception returns special value Add addFirst
addLast offerFirst
offerLast Retrieve getFirst
getLast peekFirst
peekFirst Retrieve & Remove removeFirst
removeLast pollFirst
pollLast But as it can be accessed from either end, the Queue methods we saw before now exist in two variations - one for the first and one for the last element in the Deque. But as it can be accessed from either end, the Queue methods we saw before now exist in two variations – one for the first and one for the last element in the Deque.

Again, let’s look at this in more detail. java.util.Deque throws Exception returns special value Add addFirst
addLast offerFirst
offerLast Retrieve getFirst
getLast peekFirst
peekFirst Retrieve & Remove removeFirst
removeLast pollFirst
pollLast Again, let’s look at this in more detail. Again, let’s look at this in more detail.

You can add elements to both ends of the Deque.

Just like the add method of the Queue interface, addFirst Add elements Just like the add method of the Queue interface, addFirst void addFirst(E e) Just like the add method of the Queue interface, addFirst

and addLast will throw an Exception when the Deque is full. Add elements and addLast will throw an Exception when the Deque is full. void addFirst(E e) void addLast(E e) and addLast will throw an Exception when the Deque is full.

Add elements boolean offerFirst(E e) 3 17 9 42 “offerFirst”…

…and “offerLast” will return false instead of throwing an Exception. Add elements 3 17 9 22 …and “offerLast” will return false instead of throwing an Exception. boolean offerFirst(E e) boolean offerLast(E e) …and “offerLast” will return false instead of throwing an Exception.

Please keep in mind that LinkedList has an unlimited capacity, Add elements Please keep in mind that LinkedList has an unlimited capacity, so it will never be full. boolean offerFirst(E e) boolean offerLast(E e) Please keep in mind that LinkedList has an unlimited capacity, so it will never be full.

Add elements boolean offerFirst(E e) boolean offerLast(E e) LinkedBlockingDeque on the other hand is a Deque implementation that may have a limited capacity. Okay, let’s go on. boolean offerFirst(E e) boolean offerLast(E e) LinkedBlockingDeque on the other hand is a Deque implementation-that may have a limited capacity. Okay, let’s go on.

You can retrieve elements from both ends of the Deque, You can retrieve elements from both ends of the Deque, without removing them. You can retrieve elements from both ends of the Deque, without removing them.

Retrieve elements “getFirst”… E getFirst() “getFirst”…

and “getLast” will throw an Exception when the Queue is empty, Retrieve elements and “getLast” will throw an Exception when the Queue is empty, E getFirst() E getLast() and “getLast” will throw an Exception when the Queue is empty,

Retrieve elements while “peekFirst” E peekFirst() while “peekFirst”

and “peekLast” will return false in this case. Retrieve elements and “peekLast” will return false in this case. E peekFirst() E peekLast() and “peekLast” will return false in this case.

you can retrieve and remove elements from both ends of the Deque. Retrieve elements Finally, you can retrieve and remove elements from both ends of the Deque. Finally, you can retrieve and remove elements from both ends of the Deque.

Retrieve elements “removeFirst” E removeFirst() “removeFirst”

Retrieve & remove elements and “removeLast” will throw an Exception when the Queue is empty, E removeFirst() E removeLast() and “removeLast” will throw an Exception when the Queue is empty,

Retrieve & remove elements while pollFirst E pollFirst() while pollFirst

Retrieve & remove elements and pollLast will return false in this case. E pollFirst() E pollLast() and pollLast will return false in this case.

Stack Okay. Now on to a completely different topic. Okay. Now on to a completely different topic. The Deque interface also supports the methods of the Stack data structure, “push” “peek” and “pop”. Okay. Now on to a completely different topic. The Deque interface also supports the methods of the Stack data structure, “push” “peek” and “pop”.

Therefore java.util.LinkedList can also be used as Stack.

Stack A Stack is a very simple data structure, A Stack is a very simple data structure that can only be accessed from the top. As an analogy, think of a stack of books. A Stack is a very simple data structure, that can only be accessed from the top. As an analogy, think of a stack of books.

“push” adds an element to the top of the Stack. boolean push (E e) “push” adds an element to the top of the Stack.

It is equivalent to the “addFirst” method. Stack It is equivalent to the “addFirst” method. boolean push (E e) It is equivalent to the “addFirst” method.

but does not remove an element from the top of the Stack. “peek” retrieves but does not remove an element from the top of the Stack. E peek() “peek” retrieves but does not remove an element from the top of the Stack.

It is equivalent to the “peekFirst” method. Stack It is equivalent to the “peekFirst” method. E peek() It is equivalent to the “peekFirst” method.

“pop” retrieves and removes an element from the top of the Stack. E pop() “pop” retrieves and removes an element from the top of the Stack.

It is equivalent to the “removeFirst” method. Stack It is equivalent to the “removeFirst” method. E pop() It is equivalent to the “removeFirst” method.

Copyright © 2016 Marcus Biel All rights reserved