Jump to content

Introducing a Robust and Efficient Data Structures Package for AutoIt


Recommended Posts

Posted (edited)

Here is a data structures package designed to offer robust and efficient dynamic collections, suitable for a wide range of programming needs. The included structures are List, LinkedList, DoubleLinkedList, DeQueue, and CircularQueue, each providing specific solutions for data management.

1. List

Description: List is a sequential data structure that allows for storing and manipulating collections of ordered elements. It enables efficient operations for accessing, adding, and removing elements, providing a solid foundation for many applications.

Usage:

  • Direct and fast access to elements by index.
  • Simple management of data collections.
  • Easy iteration over elements for processing or display.

2. LinkedList

Description: LinkedList implements a linked list where each element (node) points to the next. This structure is ideal for scenarios where insertion and deletion operations are frequent, as they are performed in constant time.

Usage:

  • Constant-time addition and removal of elements.
  • Flexible management of collections with dynamic sizes.
  • Sequential iteration to traverse elements.

3. DoubleLinkedList

Description: DoubleLinkedList is a doubly linked list, with each node having pointers to both the previous and next nodes. This structure allows for efficient bidirectional navigation, facilitating traversal operations in both directions.

Usage:

  • Easy bidirectional navigation.
  • Efficient insertion and deletion at both ends.
  • Advanced management of dynamic collections.

4. DeQueue (Double Ended Queue)

Description: DeQueue is a double-ended queue that allows adding and removing elements at both the beginning and the end of the queue. It combines the functionalities of stacks (LIFO) and queues (FIFO).

Usage:

  • Flexible management of elements at both ends.
  • Applications requiring dynamic access to elements.
  • Scenarios where both LIFO and FIFO operations are needed.

5. CircularQueue

Description: CircularQueue is a circular queue where the last element is linked to the first, forming a continuous loop. This structure is particularly useful for applications requiring cyclic access to elements, optimizing space utilization.

Usage:

  • Optimal memory space management.
  • Continuous loop processing scenarios.
  • Applications needing a circular queue for repetitive operations.

Conclusion

This Data Structures package offers powerful and flexible tools for managing data collections, suited to various programming needs. Each structure is designed to maximize the efficiency of data manipulation operations, providing a solid foundation for developing performant and scalable solutions.

#include-once
#include "DeQueue.au3"

; Create a deque
Local $dq = Deque()

; Append elements
$dq.append(1)
$dq.append(2)
$dq.append(3)

; Print the deque representation
ConsoleWrite("Deque: " & $dq.__repr__() & @CRLF) ; Output: [1 2 3]

; Append left
$dq.appendleft(0)

; Print the deque representation
ConsoleWrite("Deque after appendleft: " & $dq.__repr__() & @CRLF) ; Output: [0 1 2 3]

; Pop an element from the right
ConsoleWrite("Popped from right: " & $dq.pop() & @CRLF) ; Output: 3

; Print the deque representation
ConsoleWrite("Deque after pop: " & $dq.__repr__() & @CRLF) ; Output: [0 1 2]

; Pop an element from the left
ConsoleWrite("Popped from left: " & $dq.popleft() & @CRLF) ; Output: 0

; Print the deque representation
ConsoleWrite("Deque after popleft: " & $dq.__repr__() & @CRLF) ; Output: [1 2]

; Check if the deque is empty
If $dq.is_empty() Then
    ConsoleWrite("Deque is empty" & @CRLF)
Else
    ConsoleWrite("Deque is not empty" & @CRLF)
EndIf

; Get the length of the deque
ConsoleWrite("Length of deque: " & $dq.__repr__() & @CRLF) ; Output: 2

; Extend the deque
Local $array[3] = [4, 5, 6]
$dq.extend($array)

; Print the deque representation
ConsoleWrite("Deque after extending: " & $dq.__repr__() & @CRLF) ; Output: [1 2 4 5 6]

; Extend left the deque
Local $array2[3]=[-1, -2, -3]
$dq.extendleft($array2)

; Print the deque representation
ConsoleWrite("Deque after extending left: " & $dq.__repr__() & @CRLF) ; Output: [-3 -2 -1 1 2 4 5 6]

 

#include "CircularQueue.au3"

; Creating a circular queue with a maximum size of 5
Local $cq = CircularQueue(5)

; Enqueue elements
ConsoleWrite("Enqueuing elements A, B, C..." & @CRLF)
$cq.enqueue("A")
$cq.enqueue("B")
$cq.enqueue("C")

; Display the size of the circular queue
ConsoleWrite("Size of the circular queue: " & $cq.size() & @CRLF)

; Display the first element in the circular queue
ConsoleWrite("First element in the circular queue: " & $cq.first() & @CRLF)

; Dequeue an element
ConsoleWrite("Dequeuing an element..." & @CRLF)
Local $dequeued = $cq.dequeue()
ConsoleWrite("Dequeued element: " & $dequeued & @CRLF)

; Display the size of the circular queue again
ConsoleWrite("Size of the circular queue after dequeue: " & $cq.size() & @CRLF)

; Enqueue a new element
ConsoleWrite("Enqueuing element D..." & @CRLF)
$cq.enqueue("D")

; Display the size of the circular queue after enqueue
ConsoleWrite("Size of the circular queue after enqueue: " & $cq.size() & @CRLF)

; Display whether the circular queue is empty or not
If $cq.is_empty() Then
    ConsoleWrite("Circular queue is empty" & @CRLF)
Else
    ConsoleWrite("Circular queue is not empty" & @CRLF)
EndIf

; Display the first element in the circular queue again after operations
ConsoleWrite("First element in the circular queue after operations: " & $cq.first() & @CRLF)

 

 

DataStructures1.0.1.rar

Edited by Numeric1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...