Array and Linked?List.
Array
Linked List?:
Example linked list in Dart?
class Node {
late int data;
Node? next;
Node(int data) {
this.data = data;
this.next = null;
}
}
class LinkedList {
Node? head;
LinkedList() {
this.head = null;
}
// Insert a new node at the end of the linked list
void append(int data) {
Node newNode = Node(data);
if (head == null) {
head = newNode;
return;
}
Node current = head!;
while (current.next != null) {
current = current.next!;
}
current.next = newNode;
}
// Print the elements of the linked list
void printList() {
Node? current = head;
while (current != null) {
print(current.data);
current = current.next;
}
}
}
void main() {
LinkedList linkedList = LinkedList();
// Appending elements to the linked list
linkedList.append(1);
linkedList.append(2);
linkedList.append(3);
// Printing the linked list
print("Linked List:");
linkedList.printList();
}