Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DoublyLinkedList {
- private class NodeDLL {
- int data;
- NodeDLL next = null;
- NodeDLL prev = null;
- public NodeDLL(int data){
- this.data = data;
- }
- }
- NodeDLL head = null;
- NodeDLL tail = null;
- public DoublyLinkedList(){this.head = null; this.tail = null;}
- public void append(int data){
- if (head == null){
- head = new NodeDLL(data);
- tail = head;
- }
- else{
- tail.next = new NodeDLL(data);
- tail.next.prev = tail;
- tail = tail.next;
- }
- }
- public void prepend(int data){
- if (head == null){
- head = new NodeDLL(data);
- tail = head;
- }
- else{
- head.prev = new NodeDLL(data);
- head.prev.next = head;
- head = head.prev;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement