https://github.com/hasnatrasool163/flexilist.
FlexiList is a Java data structure that combines the benefits of arrays and linked lists. Like an array, it allows for efficient access to elements by index. Like a linked list, it allows for efficient insertion and deletion of elements at any position in the list.
https://github.com/hasnatrasool163/flexilist.
Last synced: 11 months ago
JSON representation
FlexiList is a Java data structure that combines the benefits of arrays and linked lists. Like an array, it allows for efficient access to elements by index. Like a linked list, it allows for efficient insertion and deletion of elements at any position in the list.
- Host: GitHub
- URL: https://github.com/hasnatrasool163/flexilist.
- Owner: Hasnatrasool163
- License: mit
- Created: 2024-06-10T06:44:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-22T19:08:45.000Z (over 1 year ago)
- Last Synced: 2025-01-09T19:02:48.113Z (about 1 year ago)
- Language: Java
- Size: 577 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FlexiList.
FlexiList is a Java data structure that combines the benefits of arrays and linked lists. Like an array, it allows for efficient access to elements by index. Like a linked list, it allows for efficient insertion and deletion of elements at any position in the list.
## Benefits Over Arrays and ArrayList
->Efficient Insertion and Deletion: FlexiList can insert or delete nodes at any position in the list in O(1) time, whereas arrays require shifting all elements after the insertion or deletion point.
->Dynamic Size: FlexiList can grow or shrink dynamically as elements are added or removed, whereas arrays have a fixed size.
->Good Memory Locality: FlexiList nodes are stored in a contiguous block of memory, making it more cache-friendly than arrays.
->Faster Insertion and Deletion: FlexiList can insert or delete nodes at any position in the list in O(1) time, whereas ArrayList requires shifting all elements after the insertion or deletion point.
->Better Memory Efficiency: FlexiList uses less memory than ArrayList because it doesn't need to store a separate array of indices.
## Class: FlexiList>
## Constructors
public FlexiList(int initialSize): Constructs a new FlexiList instance with the provided initial size.
public FlexiList(): Constructs a new FlexiList instance.
## Methods
public void add(T element): Adds an element to the list.
public void add(int index, T element): Inserts the specified element at the specified index in the list.
public T get(int index): Gets the element at the specified index.
public T getFirst(): Returns the first element in constant O(1) time.
public T getLast(): Returns the last element in constant O(1) time.
public int getInitialSize(): Returns the initial size of the list.
public int indexOf(T element): Returns the index of the specified element.
public boolean isEmpty(): Returns whether the list is empty.
public boolean contains(T element): Returns whether the list contains the specified element.
public int lastIndexOf(T element): Returns the index of the last occurrence of the specified element in the list, or -1 if the element is not found.
public void mergeSort(): Sorts the list using the merge sort algorithm.
public void remove(int index): Removes the element at the specified index.
public void clear(): Clears the list.
public void reverseList(): Reverses the order of the elements in the list.
public void set(int index, T element): Sets the element at the specified index.
public int size(): Returns the size of the list.
public void sort(Comparator comparator): Sorts the elements in the list according to the specified comparator.
public FlexiList subList(int fromIndex, int toIndex): Returns a new list containing the elements from the specified fromIndex to the specified toIndex.
public void swap(int index1, int index2): Method to swap two elements in the list.
public T[] toArray(): Returns an array containing all elements in the list.
public void trimToSize(): Trims the capacity of the list to its current size.
public Iterator iterator(): Returns an iterator over elements of type T.
public FlexiList clone(): Method provided to clone the list.
## Contributions
Everyone welcome for contributions
## Contact
hasnatrasool163@gmail.com
## Author
## Muhammad Hasnat Rasool
## Version
0.1
## MIT License all rights reserved @2024.