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

Securing SOAP Web Services with Certificate Mutual Authentication / Spring Security
Getting out of memory error while downloading multipart file using ByteArrayDataSource
Embedded Tomcat won't listen to port 80 in AWS Elastic Beanstalk
app engine with cloud storage local server
com.sun.net.HttpServer load
Manipulating hexadecimal values in java
Calling fragment layout in an Activity
Java Guava Cache : How to clear all cache entries?
return new array and increment all values by 10
I am trying to execute spring jdbc program,but at the time running the application getting exceptions
Actions stop working in Java
Google Domain API keeps returning 401/403 in responses. What am I doing wrong?
I am a bit confused as to what the code below is doing since I get the same results from both
Selecting and updating database on one click using java
JavaFX 8.0.45 and Scaling Light Effects
GAE and Local MysqlServer issue: access denied (“java.lang.RuntimePermission” “modifyThreadGroup”)

Categories

HOME
osgi
cookies
reflection
single-sign-on
path-finding
syntax
electron
tesseract
relay
react-router
kalman-filter
yahoo-oauth
sharepoint-designer
wamp
indesign
swagger-ui
ios-charts
bs4
synchronization
medical
elasticsearch-hadoop
node-pdfkit
spring-xd
quicklook
mapserver
event-handling
lombok
saxon
serilog
lucene.net
dcevm
pass-by-reference
blazemeter
emgucv
maxmind
ping
large-file-upload
quote
uisplitview
gtrendsr
force-layout
simplexml
jquery-bootgrid
theano.scan
broadcastreceiver
fedex
ibpy
sencha-touch-2.3
apple-news
parentheses
pubmed
jquery-nestable
theming
pnotify
datastax-startup
veracode
gabor-filter
windows-iot-core-10
vtigercrm
query-performance
firmata
libpng
underscore.js-templating
websitepanel
two-factor-authentication
marching-cubes
sniffer
p2
phpthumb
seaside
datagridviewcolumn
openlaszlo
intentservice
farseer
jsctypes
inbox
apc
dbconnection
html4
pygit2
type-equivalence
path-separator
nsnetservice
ticoredatasync
bubble-chart
reddot
whoosh
doh
javax.script
xfbml
suppress
nhibernate.search
mirah
web-architecture
nintendo-ds
exchange-server-2003
privilege

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App