Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node{
- Node next;
- Node previous;
- int data;
- public Node(int data){
- this.data = data;
- }
- }
- public class LinkedList {
- Node head;
- public Node push(int data){
- Node temp = this.head;
- if(head == null){
- Node newNode = new Node(data);
- newNode.next = head;
- return head = newNode;
- }
- else{
- while(temp!=null){
- temp.next = new Node(data);
- }}
- return temp;
- }
- public Node insertAtEnd(int data){
- while(head!=null){
- head.next = new Node(data);
- }
- return head.next;
- }
- public void printList() {
- Node temp = this.head;
- while (temp != null) {
- System.out.print(temp.data + "-->");
- temp = temp.next;
- }
- System.out.println(temp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement