java


can anyone explain stack ,queue,linked list in java with programs for each?


I am new to java and as well as i didn't know any other language apart from java oops concept.i am newbie to programming.so for me easy to understand, can anyone explain stack ,queue,linked list in java with programs for each?
A Stack is an abstract data type or collection where in Push,the addition of data elements to the collection, and Pop, the removal of data elements from the collection, are the major operations performed on the collection. The Push and Pop operations are performed only at one end of the Stack which is referred to as the 'top of the stack'.
In other words,a Stack can be simply defined as Last In First Out (LIFO) data structure,i.e.,the last element added at the top of the stack(In) should be the first element to be removed(Out) from the stack.
// Demonstrate the Stack class.
import java.util.*;
class StackDemo {
static void showpush(Stack st, int a) {
st.push(new Integer(a));
System.out.println("push(" + a + ")");
System.out.println("stack: " + st);
}
static void showpop(Stack st) {
System.out.print("pop -> ");
Integer a = (Integer) st.pop();
System.out.println(a);
System.out.println("stack: " + st);
}
public static void main(String args[]) {
Stack st = new Stack();
System.out.println("stack: " + st);
showpush(st, 42);
showpush(st, 66);
showpush(st, 99);
showpop(st);
showpop(st);
showpop(st);
try {
showpop(st);
} catch (EmptyStackException e) {
System.out.println("empty stack");
}
}
}
for more detail about Stack you can see this official link
Queue:
A queue supports the insert and remove operations using a first-in first-out (FIFO) discipline
For more detail: Queue
Linked List:
Java LinkedList class uses doubly linked list to store the elements. It provides a linked-list data structure. It inherits the AbstractList class and implements List and Deque interfaces.
For more detail:
official link and another
This link
geeksforgeeks is better for the beginner.
Consider starting by looking at the official Java Platform Documentation:
Stack:
The Stack class represents a last-in-first-out (LIFO) stack of
objects. It extends class Vector with five operations that allow a
vector to be treated as a stack. The usual push and pop operations are
provided, as well as a method to peek at the top item on the stack, a
method to test for whether the stack is empty, and a method to search
the stack for an item and discover how far it is from the top.
When a stack is first created, it contains no items.
...
Queue:
A collection designed for holding elements prior to processing.
Besides basic Collection operations, queues provide additional
insertion, extraction, and inspection operations. Each of these
methods exists in two forms: one throws an exception if the operation
fails, the other returns a special value (either null or false,
depending on the operation). The latter form of the insert operation
is designed specifically for use with capacity-restricted Queue
implementations; in most implementations, insert operations cannot
fail
...
LinkedList:
Doubly-linked list implementation of the List and Deque interfaces.
Implements all optional list operations, and permits all elements
(including null).
All of the operations perform as could be expected
for a doubly-linked list. Operations that index into the list will
traverse the list from the beginning or the end, whichever is closer
to the specified index.
...
I have implemented array base stack and queue .Code can be available in github location and
junit

Related Links

Serialize an Interface
Java HashMap - variable.getKey - Generic Print Method
Distributed application in a LAN with one DB server
Spring JPA - Export to csv based on table records
How can two set of values written to an Excel file in TestNG which has been taken from the script iteslf? I am using apache poi for this purpose
Group by two fields then summing BigDecimal
number of referenced method in .dex file cannot exceed 64K and java.lang.UnsupportedOperationException
Using a File to Output Arrays and Tables [duplicate]
Retrofit 2 API Can I use local file path or json string instead of url?
Strange stack at android crash report
Force Spring to use a specific class in place of another one at runtime
I can't capture ProcessingException when sending object instead of array
Oracle JDBC: Query returns 0 on Windows 10, but works perfectly on Windows 7
Android Custom Camera - Crop image inside Rectangle
Synchronizing the data with the server if not saved automatically
How to handle a consumer exception as an ack?

Categories

HOME
log4j
client
vbscript
netsuite
adb
yahoo-oauth
analysis
ip
tomcat6
modelica
export-to-csv
jsprit
footer
invantive-sql
predix
facebook-instant-articles
angular2-aot
pingfederate
entitlements
rst2pdf
elasticsearch-ruby
procdump
react-chartjs
iframe-resizer
.net-4.0
perlin-noise
vsts-build-task
asset-pipeline
wallpaper
force-layout
sequential
hexo
devextreme
adobe-premiere
jna
sfdc
spring-security-kerberos
s
logfiles
komodoedit
pebble-watch
dropbox-php
pdfclown
cudafy.net
synchronous
jquery-filter
google-web-starter-kit
paypal-express
bstr
jwplayer7
superstack
ready-api
asp.net5
freedesktop.org
qtableview
sdhc
comobject
wireshark-dissector
purge
operation
unity3d-gui
streambase
document-classification
stxxl
flexmojos
gnu-smalltalk
mysqltuner
page-layout
ora-00911
batterylevel
random-seed
android-hardware
quickdialog
cisco-jtapi
venn-diagram
newtonscript
labwindows
appconkit
gwt-ext
deobfuscation
disclosure
dentrix
brewmp
virtual-functions
swing-app-framework
eqatec
defensive-programming
django-notification

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App