JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label Linked-List. Show all posts
Showing posts with label Linked-List. Show all posts

Implement stack using Linked List in java data structure and algorithm in data structure and algorithm

1:35 AM
Implement stack using Linked List in java data structure and algorithm in data structure and algorithm The stack is an abstract data type that demonstrates Last in first out (LIFO) behavior. We will implement the same behavior using Linked List. There are two most important operations of Stack: Push: We will push elements to the beginning of the linked list to demonstrate the push behavior of the stack. Pop: We will remove the first element of linked list to demonstrate the pop behavior of Stack. Java Program: Let's create a java program to create a stack using Linked List. package org.arpit.java2blog; public class LinkedListStack { private Node head; // the first node // nest class to define linkedlist node private class Node { int value; Node next; } public LinkedListStack() { head = null; } // Remove value from the beginning of the list for demonstrating behaviour of stack public int pop() throws LinkedListEmptyException { if (head ...

Explain about Linked List?

10:28 PM
Linked List Linked List can be defined as a collection of objects called  nodes  that are randomly stored in the memory. A node contains two fields i.e. data stored at that particular address and the pointer which contains the address of the next node in the memory. The last node of the list contains a pointer to the null. Uses of Linked List The list is not required to be contiguously present in the memory. The node can reside any where in the memory and linked together to make a list. This achieves optimized utilization of space. list size is limited to the memory size and doesn't need to be declared in advance. Empty node can not be present in the linked list. We can store values of primitive types or objects in the singly linked list. Why use linked list over array? Till now, we were using array data structure to organize the group of elements that are to be stored individually in the memory. However, Array has several advantages and disadvantages which...

.