import
java.util.*;
import
java.util.Collection;
public
class
LinkedListImpl<E> {
private
LinkedList<E> linkedList;
public
LinkedListImpl()
{
linkedList =
new
LinkedList<E>();
}
public
LinkedListImpl(Collection<?
extends
E> c)
{
linkedList =
new
LinkedList<E>(c);
}
public
boolean
add(E e)
{
return
linkedList.add(e);
}
public
void
add(
int
index, E element)
{
linkedList.add(index, element);
}
public
boolean
addAll(Collection<?
extends
E> c)
{
return
linkedList.addAll(c);
}
public
boolean
addAll(
int
index,
Collection<?
extends
E> c)
{
return
linkedList.addAll(index, c);
}
public
void
addFirst(E e) { linkedList.addFirst(e); }
public
void
addLast(E e) { linkedList.addLast(e); }
public
void
clear() { linkedList.clear(); }
public
Object clone() {
return
linkedList.clone(); }
public
boolean
contains(Object o)
{
return
linkedList.contains(o);
}
public
Iterator<E> descendingIterator()
{
return
linkedList.descendingIterator();
}
public
E element() {
return
linkedList.element(); }
public
E get(
int
index)
{
return
linkedList.get(index);
}
public
E getFirst() {
return
linkedList.getFirst(); }
public
E getLast() {
return
linkedList.getLast(); }
public
int
indexOf(Object o)
{
return
linkedList.indexOf(o);
}
public
boolean
isEmpty()
{
return
linkedList.isEmpty();
}
public
Iterator<E> iterator()
{
return
linkedList.iterator();
}
public
int
lastIndexOf(Object o)
{
return
linkedList.lastIndexOf(o);
}
public
ListIterator<E> listIterator()
{
return
linkedList.listIterator();
}
public
ListIterator<E> listIterator(
int
index)
{
return
linkedList.listIterator(index);
}
public
boolean
offer(E e)
{
return
linkedList.offer(e);
}
public
boolean
offerFirst(E e)
{
return
linkedList.offerFirst(e);
}
public
boolean
offerLast(E e)
{
return
linkedList.offerLast(e);
}
public
E peek() {
return
linkedList.peek(); }
public
E peekFirst() {
return
linkedList.peekFirst(); }
public
E peekLast() {
return
linkedList.peekLast(); }
public
E poll() {
return
linkedList.poll(); }
public
E pollFirst() {
return
linkedList.pollFirst(); }
public
E pollLast() {
return
linkedList.peekLast(); }
public
E pop() {
return
linkedList.pop(); }
public
void
push(E e) { linkedList.push(e); }
public
E remove(
int
index)
{
return
linkedList.remove(index);
}
public
boolean
remove(Object o)
{
return
linkedList.remove(o);
}
public
boolean
removeAll(Collection<?> c)
{
return
linkedList.removeAll(c);
}
public
E removeFirst()
{
return
linkedList.removeFirst();
}
public
boolean
removeFirstOccurrence(Object o)
{
return
linkedList.removeFirstOccurrence(o);
}
public
E removeLast()
{
return
linkedList.removeLast();
}
public
boolean
removeLastOccurrence(Object o)
{
return
linkedList.removeLastOccurrence(o);
}
public
boolean
retainAll(Collection<?> c)
{
return
linkedList.removeAll(c);
}
public
E set(
int
index, E element)
{
return
linkedList.set(index, element);
}
public
int
size() {
return
linkedList.size(); }
public
List<E> subList(
int
fromIndex,
int
toIndex)
{
return
linkedList.subList(fromIndex, toIndex);
}
public
Object[] toArray()
{
return
linkedList.toArray();
}
public
<T> T[] toArray(T[] a)
{
return
linkedList.toArray(a);
}
public
static
void
main(String... arg)
{
LinkedListImpl<Integer> linkedList
=
new
LinkedListImpl<>();
linkedList.add(
100
);
linkedList.add(
20
);
linkedList.addFirst(
101
);
linkedList.addLast(
200
);
Set<Integer> set =
new
HashSet<Integer>();
set.add(
101
);
set.add(
30
);
set.add(
32
);
linkedList.addAll(
4
, set);
if
(linkedList.contains(
300
))
System.out.println(
"the linked list contains 300"
);
else
System.out.println(
"the linked list does not contain 300"
);
System.out.println(
"the elements in descending order is"
);
Iterator<Integer> descendingitr
= linkedList.descendingIterator();
while
(descendingitr.hasNext()) {
System.out.print(descendingitr.next() +
"\t"
);
}
System.out.println();
System.out.println(
"the head of this list is "
+ linkedList.element());
System.out.println(
"the element at index 2 is "
+ linkedList.get(
2
));
System.out.println(
"the element first pos is "
+ linkedList.getFirst());
System.out.println(
"the element at last pos is"
+ linkedList.getLast());
System.out.println(
"the index of element 200 is "
+ linkedList.indexOf(
200
));
System.out.println(
"the last index of element 101 is "
+ linkedList.lastIndexOf(
101
));
System.out.println(
"the elements of list are"
);
Iterator<Integer> itr = linkedList.iterator();
while
(itr.hasNext()) {
System.out.print(itr.next() +
"\t"
);
}
System.out.println();
linkedList.offer(
45
);
linkedList.offerFirst(
32
);
linkedList.offerLast(
19
);
System.out.println(
"the head of the linkedlist is "
+ linkedList.peek());
System.out.println(
"the first element of linkedList is "
+ linkedList.peekFirst());
System.out.println(
"the last element of linked List is "
+ linkedList.peekLast());
System.out.println(
"the elements of list are"
);
itr = linkedList.iterator();
while
(itr.hasNext()) {
System.out.print(itr.next() +
"\t"
);
}
System.out.println();
System.out.println(
"the first element of linkedList is (poll) "
+ linkedList.poll());
System.out.println(
"the first element polled is "
+ linkedList.pollFirst());
System.out.println(
"the last element polled is "
+ linkedList.pollLast());
linkedList.push(
36
);
System.out.println(
"the element popped from linked List is "
+ linkedList.pop());
System.out.println(
"index 3 element removed from list "
+ linkedList.remove(
3
));
System.out.println(
"last occurrence of 101 removed "
+ linkedList.removeLastOccurrence(
101
));
linkedList.clear();
if
(linkedList.isEmpty())
System.out.println(
"the linkedList is empty"
);
else
System.out.println(
"the linked list is not empty"
);
}
}