Java Program to Implement VList Last Updated : 17 Feb, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report VList is a data structure that combines fast indexing of arrays with the easy extension of singly-linked lists. VList generally supports the following functions. Insert ElementGet Element at index kClear ListDisplay ListEtc. VList has rows connected as Singly Linked List where the Nth row contains maximum 2^N elements. Example: VList: [2] ↓ [1, 3] ↓ [5, 1, 5, 8] ↓ [10, 12, 5, 9, 1, 0, 8, 7] ↓ [3, 5, 7] VList is Filled first Left to Right Then Top to Bottom. Implementation: Java // Java Program to Implement VList import java.io.*; import java.util.*; // This will act as each row of VList class VListNode { VListNode next; List<Integer> list; public VListNode() { next = null; list = new ArrayList<Integer>(); } } class VList { private VListNode start; private VListNode end; private int nodeNumber; private int size; // Constructor of VList public VList() { start = null; end = null; nodeNumber = 0; size = 0; } // Check if VList is Empty or Not public boolean isEmpty() { return start == null; } // Get Number of Elements in VList public void getSize() { System.out.println("VList size : " + size); System.out.println(); } // Make VList Empty public void clearVList() { start = null; end = null; nodeNumber = 0; size = 0; System.out.println("VList is Cleared"); System.out.println(); } // Insert a new Element in VList public void insert(int x) { size++; int n = (int)Math.pow(2, nodeNumber); if (start == null) { start = new VListNode(); start.list.add(x); end = start; return; } if (end.list.size() + 1 <= n) { end.list.add(x); } else { nodeNumber++; VListNode tempNode = new VListNode(); tempNode.list.add(x); end.next = tempNode; end = tempNode; } } // Get value of Element at index k in VList public void searchElementWithPosition(int k) { System.out.print("Element at position " + k + " is = "); if (k < 1 || k > size) { System.out.println("Does not Exist"); System.out.println(); return; } k--; VListNode startTemp = start; while (k >= startTemp.list.size()) { k -= startTemp.list.size(); startTemp = startTemp.next; } System.out.println(startTemp.list.get(k)); System.out.println(); } // Print full VList public void displayVList() { System.out.print("VList : "); if (size == 0) { System.out.print("empty\n"); return; } System.out.println(); VListNode startTemp = start; int num = 0; while (startTemp != null) { for (int i = 0; i < startTemp.list.size(); i++) { System.out.print(startTemp.list.get(i) + " "); } System.out.println(); startTemp = startTemp.next; num++; } System.out.println(); } } class GFG { public static void main(String[] args) { // Driver Code // Initialize Vlist VList vlist = new VList(); int[] arr = new int[] { 9, 1, 5, 4, 3, 5, 2, 1, 0, 8 }; // Insert Elements in VList for (int val : arr) { vlist.insert(val); } // Display VList vlist.displayVList(); // Search 1st Element vlist.searchElementWithPosition(1); // Search 5th Element vlist.searchElementWithPosition(5); // Search 8th Element vlist.searchElementWithPosition(8); vlist.getSize(); // Make List Empty vlist.clearVList(); System.out.println("Vlist IsEmpty = " + vlist.isEmpty()); } } OutputVList : 9 1 5 4 3 5 2 1 0 8 Element at position 1 is = 9 Element at position 5 is = 3 Element at position 8 is = 1 VList size : 10 VList is Cleared Vlist IsEmpty = true Time Complexity: Insert operation: O(1) Search operation: O(log(n))Display: O(n)Get Size & Check Empty: O(1) Comment More infoAdvertise with us Next Article Implementing Sorted Vector in Java P pratikraut0000 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Practice Tags : Java Similar Reads Implementing Sorted Vector in Java Vector is a class that implements the List interface. It is a type of dynamic array that means the size of a vector can be grown or shrink during the execution of the program. The initial size of the vector is 10 and if we insert more than 10 elements then the size of the vector is increased by 100% 3 min read Java Program to Copy Elements of ArrayList to Vector Vector implements List Interface, like ArrayList it also maintains insertion order but it is rarely used in the non-thread environment as it is synchronized, and due to which it gives a poor performance in adding, searching, deleting, and updating of its elements. To copy elements from one collectio 4 min read Java Program to Implement ArrayBlockingQueue API ArrayBlockingQueue class is a member of the Java Collection framework. ArrayBlockingQueue is a bounded blocking queue. The term bounded, means that the size of the Queue is fixed and cannot be changed. Any attempt to put element/elements into a full queue will lead to blocking operation. Similarly, 7 min read Program to Convert a Vector to List in Java Given a Vector, the task is to Convert Vector to List in Java Examples: Input: Vector: [1, 2, 3, 4, 5] Output: List: [1, 2, 3, 4, 5] Input : Vector = [a, b, c, d, e, f] Output : List = [a, b, c, d, e, f] Using Collections.list() method Syntax: List list = Collections.list(vec.elements()); Approach: 3 min read Program to Convert List to Stream in Java The List is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. List Interface is implemented by ArrayList, LinkedList, Vector and Stack class 3 min read Program to Convert List to Stream in Java The List is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. List Interface is implemented by ArrayList, LinkedList, Vector and Stack class 3 min read Like