Retranslate the complete English edition from Simplified Chinese (#2010)

* Retranslate the complete English edition from Simplified Chinese

* Polish three English explanations after reader-focused review
This commit is contained in:
Yudong Jin
2026-10-31 03:35:51 +08:00
committed by GitHub
parent ef46e2ed95
commit 14c314c08c
1502 changed files with 29459 additions and 23517 deletions

View File

@@ -4,11 +4,11 @@
* Author: liuyuxin (gvenusleo@gmail.com)
*/
/* Double-ended queue based on circular array implementation */
/* Deque implemented with a circular array */
class ArrayDeque {
late List<int> _nums; // Array for storing double-ended queue elements
late int _front; // Front pointer, points to the front of the queue element
late int _queSize; // Double-ended queue length
late List<int> _nums; // Array for storing deque elements
late int _front; // Front pointer, pointing to the first element
late int _queSize; // Deque size
/* Constructor */
ArrayDeque(int capacity) {
@@ -16,71 +16,71 @@ class ArrayDeque {
this._front = this._queSize = 0;
}
/* Get the capacity of the double-ended queue */
/* Get the deque capacity */
int capacity() {
return _nums.length;
}
/* Get the length of the double-ended queue */
/* Get the deque size */
int size() {
return _queSize;
}
/* Check if the double-ended queue is empty */
/* Check whether the deque is empty */
bool isEmpty() {
return _queSize == 0;
}
/* Calculate circular array index */
/* Calculate an index in the circular array */
int index(int i) {
// Use modulo operation to wrap the array head and tail together
// When i passes the tail of the array, return to the head
// When i passes the head of the array, return to the tail
// Use modulo to connect the end of the array to its beginning
// When i passes the end of the array, wrap around to the beginning
// When i passes the beginning of the array, wrap around to the end
return (i + capacity()) % capacity();
}
/* Front of the queue enqueue */
/* Enqueue at the front */
void pushFirst(int _num) {
if (_queSize == capacity()) {
throw Exception("Double-ended queue is full");
throw Exception("Deque is full");
}
// Use modulo operation to wrap front around to the tail after passing the head of the array
// Use modulo operation to wrap _front from array head back to tail
// Move the front pointer one position to the left
// Use modulo to wrap _front to the end when it passes the beginning of the array
_front = index(_front - 1);
// Add _num to queue front
// Add _num to the front
_nums[_front] = _num;
_queSize++;
}
/* Rear of the queue enqueue */
/* Enqueue at the rear */
void pushLast(int _num) {
if (_queSize == capacity()) {
throw Exception("Double-ended queue is full");
throw Exception("Deque is full");
}
// Use modulo operation to wrap rear around to the head after passing the tail of the array
// Calculate the rear pointer, which points one position past the last element
int rear = index(_front + _queSize);
// Add _num to queue rear
// Add _num to the rear
_nums[rear] = _num;
_queSize++;
}
/* Rear of the queue dequeue */
/* Dequeue from the front */
int popFirst() {
int _num = peekFirst();
// Move front pointer right by one
// Move the front pointer one position to the right
_front = index(_front + 1);
_queSize--;
return _num;
}
/* Access rear of the queue element */
/* Dequeue from the rear */
int popLast() {
int _num = peekLast();
_queSize--;
return _num;
}
/* Return list for printing */
/* Access the front element */
int peekFirst() {
if (isEmpty()) {
throw Exception("Deque is empty");
@@ -88,19 +88,19 @@ class ArrayDeque {
return _nums[_front];
}
/* Driver Code */
/* Access the rear element */
int peekLast() {
if (isEmpty()) {
throw Exception("Deque is empty");
}
// Initialize double-ended queue
// Calculate the index of the last element
int last = index(_front + _queSize - 1);
return _nums[last];
}
/* Return array for printing */
/* Return an array for printing */
List<int> toArray() {
// Elements enqueue
// Convert only the list elements within the occupied range
List<int> res = List.filled(_queSize, 0);
for (int i = 0, j = _front; i < _queSize; i++, j++) {
res[i] = _nums[index(j)];
@@ -109,38 +109,38 @@ class ArrayDeque {
}
}
/* Driver Code */
/* Driver code */
void main() {
/* Get the length of the double-ended queue */
/* Initialize the deque */
final ArrayDeque deque = ArrayDeque(10);
deque.pushLast(3);
deque.pushLast(2);
deque.pushLast(5);
print("Deque deque = ${deque.toArray()}");
/* Update element */
/* Access an element */
final int peekFirst = deque.peekFirst();
print("Front element peekFirst = $peekFirst");
final int peekLast = deque.peekLast();
print("Rear element peekLast = $peekLast");
/* Elements enqueue */
/* Enqueue elements */
deque.pushLast(4);
print("After element 4 enqueues at rear, deque = ${deque.toArray()}");
print("After enqueuing 4 at the rear, deque = ${deque.toArray()}");
deque.pushFirst(1);
print("After element 1 enqueues at front, deque = ${deque.toArray()}");
print("After enqueuing 1 at the front, deque = ${deque.toArray()}");
/* Element dequeue */
/* Dequeue an element */
final int popLast = deque.popLast();
print("Dequeue rear element = $popLast, after rear dequeue deque = ${deque.toArray()}");
print("Element dequeued from the rear = $popLast; after dequeuing from the rear, deque = ${deque.toArray()}");
final int popFirst = deque.popFirst();
print("Dequeue front element = $popFirst, after front dequeue deque = ${deque.toArray()}");
print("Element dequeued from the front = $popFirst; after dequeuing from the front, deque = ${deque.toArray()}");
/* Get the length of the double-ended queue */
/* Get the deque size */
final int size = deque.size();
print("Deque length size = $size");
print("Deque size = $size");
/* Check if the double-ended queue is empty */
/* Check whether the deque is empty */
final bool isEmpty = deque.isEmpty();
print("Is deque empty = $isEmpty");
print("Is the deque empty = $isEmpty");
}

View File

@@ -4,28 +4,28 @@
* Author: liuyuxin (gvenusleo@gmail.com)
*/
/* Queue based on circular array implementation */
/* Queue implemented with a circular array */
class ArrayQueue {
late List<int> _nums; // Array for storing queue elements
late int _front; // Front pointer, points to the front of the queue element
late int _queSize; // Queue length
late List<int> _nums; // Array that stores the queue elements
late int _front; // Front pointer, pointing to the first element
late int _queSize; // Queue size
ArrayQueue(int capacity) {
_nums = List.filled(capacity, 0);
_front = _queSize = 0;
}
/* Get the capacity of the queue */
/* Get the queue capacity */
int capaCity() {
return _nums.length;
}
/* Get the length of the queue */
/* Get the queue size */
int size() {
return _queSize;
}
/* Check if the queue is empty */
/* Check whether the queue is empty */
bool isEmpty() {
return _queSize == 0;
}
@@ -35,10 +35,10 @@ class ArrayQueue {
if (_queSize == capaCity()) {
throw Exception("Queue is full");
}
// Use modulo operation to wrap rear around to the head after passing the tail of the array
// Add num to the rear of the queue
// Calculate the rear pointer, which points one position past the last element
// Use modulo to wrap rear to the beginning when it passes the end of the array
int rear = (_front + _queSize) % capaCity();
// Add _num to queue rear
// Add _num to the rear
_nums[rear] = _num;
_queSize++;
}
@@ -46,13 +46,13 @@ class ArrayQueue {
/* Dequeue */
int pop() {
int _num = peek();
// Move front pointer backward by one position, if it passes the tail, return to array head
// Advance the front pointer by one position, wrapping to the beginning if it passes the end
_front = (_front + 1) % capaCity();
_queSize--;
return _num;
}
/* Return list for printing */
/* Access the front element */
int peek() {
if (isEmpty()) {
throw Exception("Queue is empty");
@@ -60,9 +60,9 @@ class ArrayQueue {
return _nums[_front];
}
/* Return Array */
/* Return an array */
List<int> toArray() {
// Elements enqueue
// Convert only the list elements within the occupied range
final List<int> res = List.filled(_queSize, 0);
for (int i = 0, j = _front; i < _queSize; i++, j++) {
res[i] = _nums[j % capaCity()];
@@ -71,13 +71,13 @@ class ArrayQueue {
}
}
/* Driver Code */
/* Driver code */
void main() {
/* Access front of the queue element */
/* Initialize the queue */
final int capacity = 10;
final ArrayQueue queue = ArrayQueue(capacity);
/* Elements enqueue */
/* Enqueue elements */
queue.push(1);
queue.push(3);
queue.push(2);
@@ -85,26 +85,26 @@ void main() {
queue.push(4);
print("Queue queue = ${queue.toArray()}");
/* Return list for printing */
/* Access the front element */
final int peek = queue.peek();
print("Front element peek = $peek");
/* Element dequeue */
/* Dequeue an element */
final int pop = queue.pop();
print("Dequeue element pop = $pop, after dequeue queue = ${queue.toArray()}");
print("Dequeued element pop = $pop; after dequeuing, queue = ${queue.toArray()}");
/* Get queue length */
/* Get the queue size */
final int size = queue.size();
print("Queue length size = $size");
print("Queue size = $size");
/* Check if the queue is empty */
/* Check whether the queue is empty */
final bool isEmpty = queue.isEmpty();
print("Is queue empty = $isEmpty");
print("Is the queue empty = $isEmpty");
/* Test circular array */
/* Test the circular array */
for (int i = 0; i < 10; i++) {
queue.push(i);
queue.pop();
print("After round $i enqueue + dequeue, queue = ${queue.toArray()}");
print("Round $i: after enqueue + dequeue, queue = ${queue.toArray()}");
}
}

View File

@@ -4,19 +4,19 @@
* Author: liuyuxin (gvenusleo@gmail.com)
*/
/* Stack based on array implementation */
/* Stack implemented with an array */
class ArrayStack {
late List<int> _stack;
ArrayStack() {
_stack = [];
}
/* Get the length of the stack */
/* Get the stack size */
int size() {
return _stack.length;
}
/* Check if the stack is empty */
/* Check whether the stack is empty */
bool isEmpty() {
return _stack.isEmpty;
}
@@ -34,7 +34,7 @@ class ArrayStack {
return _stack.removeLast();
}
/* Return list for printing */
/* Access the top element */
int peek() {
if (isEmpty()) {
throw Exception("Stack is empty");
@@ -42,16 +42,16 @@ class ArrayStack {
return _stack.last;
}
/* Convert stack to Array and return */
/* Return the underlying stack array */
List<int> toArray() => _stack;
}
/* Driver Code */
/* Driver code */
void main() {
/* Access top of the stack element */
/* Initialize the stack */
final ArrayStack stack = ArrayStack();
/* Elements push onto stack */
/* Push elements onto the stack */
stack.push(1);
stack.push(3);
stack.push(2);
@@ -59,19 +59,19 @@ void main() {
stack.push(4);
print("Stack stack = ${stack.toArray()}");
/* Return list for printing */
/* Access the top element */
final int peek = stack.peek();
print("Top element peek = $peek");
/* Element pop from stack */
/* Pop an element from the stack */
final int pop = stack.pop();
print("Pop element pop = $pop, after pop stack = ${stack.toArray()}");
print("Popped element pop = $pop; after popping, stack = ${stack.toArray()}");
/* Get the length of the stack */
/* Get the stack size */
final int size = stack.size();
print("Stack length size = $size");
print("Stack size = $size");
/* Check if empty */
/* Check whether it is empty */
final bool isEmpty = stack.isEmpty();
print("Is stack empty = $isEmpty");
print("Is the stack empty = $isEmpty");
}

View File

@@ -7,36 +7,36 @@
import 'dart:collection';
void main() {
/* Get the length of the double-ended queue */
/* Initialize the deque */
final Queue<int> deque = Queue();
deque.addFirst(3);
deque.addLast(2);
deque.addLast(5);
print("Deque deque = $deque");
/* Update element */
/* Access an element */
final int peekFirst = deque.first;
print("Front element peekFirst = $peekFirst");
final int peekLast = deque.last;
print("Rear element peekLast = $peekLast");
/* Elements enqueue */
/* Enqueue elements */
deque.addLast(4);
print("After element 4 enqueues at rear, deque = $deque");
print("After enqueuing 4 at the rear, deque = $deque");
deque.addFirst(1);
print("After element 1 enqueues at front, deque = $deque");
print("After enqueuing 1 at the front, deque = $deque");
/* Element dequeue */
/* Dequeue an element */
final int popLast = deque.removeLast();
print("Dequeue rear element = $popLast, after rear dequeue deque = $deque");
print("Element dequeued from the rear = $popLast; after dequeuing from the rear, deque = $deque");
final int popFirst = deque.removeFirst();
print("Dequeue front element = $popFirst, after front dequeue deque = $deque");
print("Element dequeued from the front = $popFirst; after dequeuing from the front, deque = $deque");
/* Get the length of the double-ended queue */
/* Get the deque size */
final int size = deque.length;
print("Deque length size = $size");
print("Deque size = $size");
/* Check if the double-ended queue is empty */
/* Check whether the deque is empty */
final bool isEmpty = deque.isEmpty;
print("Is deque empty = $isEmpty");
print("Is the deque empty = $isEmpty");
}

View File

@@ -7,29 +7,29 @@
/* Doubly linked list node */
class ListNode {
int val; // Node value
ListNode? next; // Successor node reference
ListNode? prev; // Predecessor node reference
ListNode? next; // Reference to the next node
ListNode? prev; // Reference to the previous node
ListNode(this.val, {this.next, this.prev});
}
/* Deque implemented based on doubly linked list */
/* Deque implemented with a doubly linked list */
class LinkedListDeque {
late ListNode? _front; // Head node _front
late ListNode? _rear; // Tail node _rear
int _queSize = 0; // Length of the double-ended queue
int _queSize = 0; // Deque size
LinkedListDeque() {
this._front = null;
this._rear = null;
}
/* Get deque length */
/* Get the deque size */
int size() {
return this._queSize;
}
/* Check if the double-ended queue is empty */
/* Check whether the deque is empty */
bool isEmpty() {
return size() == 0;
}
@@ -38,89 +38,89 @@ class LinkedListDeque {
void push(int _num, bool isFront) {
final ListNode node = ListNode(_num);
if (isEmpty()) {
// If list is empty, let both _front and _rear point to node
// If the linked list is empty, make both _front and _rear point to node
_front = _rear = node;
} else if (isFront) {
// Front of the queue enqueue operation
// Enqueue at the front
// Add node to the head of the linked list
_front!.prev = node;
node.next = _front;
_front = node; // Update head node
_front = node; // Update the head node
} else {
// Rear of the queue enqueue operation
// Enqueue at the rear
// Add node to the tail of the linked list
_rear!.next = node;
node.prev = _rear;
_rear = node; // Update tail node
_rear = node; // Update the tail node
}
_queSize++; // Update queue length
_queSize++; // Update the queue size
}
/* Front of the queue enqueue */
/* Enqueue at the front */
void pushFirst(int _num) {
push(_num, true);
}
/* Rear of the queue enqueue */
/* Enqueue at the rear */
void pushLast(int _num) {
push(_num, false);
}
/* Dequeue operation */
int? pop(bool isFront) {
// If queue is empty, return null directly
// If the queue is empty, return null immediately
if (isEmpty()) {
return null;
}
final int val;
// When the deque has one element, front and rear point to the same node
// When the queue size is 1, the head and tail point to the same node
if (_queSize == 1) {
val = _front!.val;
_front = null;
_rear = null;
}
// Temporarily store head node value
// Dequeue from the front
else if (isFront) {
val = _front!.val; // Delete head node
// Delete head node
val = _front!.val; // Save the head node value
// Remove the head node
ListNode? fNext = _front!.next;
fNext!.prev = null;
_front!.next = null;
_front = fNext; // Update head node
// Temporarily store tail node value
_front = fNext; // Update the head node
// Dequeue from the rear
} else {
val = _rear!.val; // Delete tail node
// Update tail node
val = _rear!.val; // Save the tail node value
// Remove the tail node
ListNode? rPrev = _rear!.prev;
rPrev!.next = null;
_rear!.prev = null;
_rear = rPrev; // Update tail node
_rear = rPrev; // Update the tail node
}
_queSize--; // Update queue length
_queSize--; // Update the queue size
return val;
}
/* Rear of the queue dequeue */
/* Dequeue from the front */
int? popFirst() {
return pop(true);
}
/* Access rear of the queue element */
/* Dequeue from the rear */
int? popLast() {
return pop(false);
}
/* Return list for printing */
/* Access the front element */
int? peekFirst() {
return _front?.val;
}
/* Driver Code */
/* Access the rear element */
int? peekLast() {
return _rear?.val;
}
/* Return array for printing */
/* Return an array for printing */
List<int> toArray() {
ListNode? node = _front;
final List<int> res = [];
@@ -132,38 +132,38 @@ class LinkedListDeque {
}
}
/* Driver Code */
/* Driver code */
void main() {
/* Get the length of the double-ended queue */
/* Initialize the deque */
final LinkedListDeque deque = LinkedListDeque();
deque.pushLast(3);
deque.pushLast(2);
deque.pushLast(5);
print("Deque deque = ${deque.toArray()}");
/* Update element */
/* Access an element */
int? peekFirst = deque.peekFirst();
print("Front element peekFirst = $peekFirst");
int? peekLast = deque.peekLast();
print("Rear element peekLast = $peekLast");
/* Elements enqueue */
/* Enqueue elements */
deque.pushLast(4);
print("After element 4 enqueues at rear, deque = ${deque.toArray()}");
print("After enqueuing 4 at the rear, deque = ${deque.toArray()}");
deque.pushFirst(1);
print("After element 1 enqueues at front, deque = ${deque.toArray()}");
print("After enqueuing 1 at the front, deque = ${deque.toArray()}");
/* Element dequeue */
/* Dequeue an element */
int? popLast = deque.popLast();
print("Dequeue rear element = $popLast, after rear dequeue deque = ${deque.toArray()}");
print("Element dequeued from the rear = $popLast; after dequeuing from the rear, deque = ${deque.toArray()}");
int? popFirst = deque.popFirst();
print("Dequeue front element = $popFirst, after front dequeue deque = ${deque.toArray()}");
print("Element dequeued from the front = $popFirst; after dequeuing from the front, deque = ${deque.toArray()}");
/* Get the length of the double-ended queue */
/* Get the deque size */
int size = deque.size();
print("Deque length size = $size");
print("Deque size = $size");
/* Check if the double-ended queue is empty */
/* Check whether the deque is empty */
bool isEmpty = deque.isEmpty();
print("Is deque empty = $isEmpty");
print("Is the deque empty = $isEmpty");
}

View File

@@ -6,37 +6,37 @@
import '../utils/list_node.dart';
/* Queue based on linked list implementation */
/* Queue implemented with a linked list */
class LinkedListQueue {
ListNode? _front; // Head node _front
ListNode? _rear; // Tail node _rear
int _queSize = 0; // Queue length
int _queSize = 0; // Queue size
LinkedListQueue() {
_front = null;
_rear = null;
}
/* Get the length of the queue */
/* Get the queue size */
int size() {
return _queSize;
}
/* Check if the queue is empty */
/* Check whether the queue is empty */
bool isEmpty() {
return _queSize == 0;
}
/* Enqueue */
void push(int _num) {
// Add _num after tail node
// Add _num after the tail node
final node = ListNode(_num);
// If the queue is empty, make both front and rear point to the node
// If the queue is empty, make both the head and tail point to this node
if (_front == null) {
_front = node;
_rear = node;
} else {
// If the queue is not empty, add the node after the tail node
// If the queue is not empty, add this node after the tail node
_rear!.next = node;
_rear = node;
}
@@ -46,13 +46,13 @@ class LinkedListQueue {
/* Dequeue */
int pop() {
final int _num = peek();
// Delete head node
// Remove the head node
_front = _front!.next;
_queSize--;
return _num;
}
/* Return list for printing */
/* Access the front element */
int peek() {
if (_queSize == 0) {
throw Exception('Queue is empty');
@@ -60,7 +60,7 @@ class LinkedListQueue {
return _front!.val;
}
/* Convert linked list to Array and return */
/* Convert the linked list to an array and return it */
List<int> toArray() {
ListNode? node = _front;
final List<int> queue = [];
@@ -72,12 +72,12 @@ class LinkedListQueue {
}
}
/* Driver Code */
/* Driver code */
void main() {
/* Access front of the queue element */
/* Initialize the queue */
final queue = LinkedListQueue();
/* Elements enqueue */
/* Enqueue elements */
queue.push(1);
queue.push(3);
queue.push(2);
@@ -85,19 +85,19 @@ void main() {
queue.push(4);
print("Queue queue = ${queue.toArray()}");
/* Return list for printing */
/* Access the front element */
final int peek = queue.peek();
print("Front element peek = $peek");
/* Element dequeue */
/* Dequeue an element */
final int pop = queue.pop();
print("Dequeue element pop = $pop, after dequeue queue = ${queue.toArray()}");
print("Dequeued element pop = $pop; after dequeuing, queue = ${queue.toArray()}");
/* Get the length of the queue */
/* Get the queue size */
final int size = queue.size();
print("Queue length size = $size");
print("Queue size = $size");
/* Check if the queue is empty */
/* Check whether the queue is empty */
final bool isEmpty = queue.isEmpty();
print("Is queue empty = $isEmpty");
print("Is the queue empty = $isEmpty");
}

View File

@@ -6,21 +6,21 @@
import '../utils/list_node.dart';
/* Stack implemented based on linked list class */
/* Stack implemented with a linked list */
class LinkedListStack {
ListNode? _stackPeek; // Use head node as stack top
int _stkSize = 0; // Stack length
ListNode? _stackPeek; // Use the head node as the stack top
int _stkSize = 0; // Stack size
LinkedListStack() {
_stackPeek = null;
}
/* Get the length of the stack */
/* Get the stack size */
int size() {
return _stkSize;
}
/* Check if the stack is empty */
/* Check whether the stack is empty */
bool isEmpty() {
return _stkSize == 0;
}
@@ -41,7 +41,7 @@ class LinkedListStack {
return _num;
}
/* Return list for printing */
/* Access the top element */
int peek() {
if (_stackPeek == null) {
throw Exception("Stack is empty");
@@ -49,7 +49,7 @@ class LinkedListStack {
return _stackPeek!.val;
}
/* Convert linked list to List and return */
/* Convert the linked list to a List and return it */
List<int> toList() {
ListNode? node = _stackPeek;
List<int> list = [];
@@ -62,12 +62,12 @@ class LinkedListStack {
}
}
/* Driver Code */
/* Driver code */
void main() {
/* Access top of the stack element */
/* Initialize the stack */
final LinkedListStack stack = LinkedListStack();
/* Elements push onto stack */
/* Push elements onto the stack */
stack.push(1);
stack.push(3);
stack.push(2);
@@ -75,19 +75,19 @@ void main() {
stack.push(4);
print("Stack stack = ${stack.toList()}");
/* Return list for printing */
/* Access the top element */
final int peek = stack.peek();
print("Top element peek = $peek");
/* Element pop from stack */
/* Pop an element from the stack */
final int pop = stack.pop();
print("Pop element pop = $pop, after pop stack = ${stack.toList()}");
print("Popped element pop = $pop; after popping, stack = ${stack.toList()}");
/* Get the length of the stack */
/* Get the stack size */
final int size = stack.size();
print("Stack length size = $size");
print("Stack size = $size");
/* Check if empty */
/* Check whether it is empty */
final bool isEmpty = stack.isEmpty();
print("Is stack empty = $isEmpty");
print("Is the stack empty = $isEmpty");
}

View File

@@ -7,11 +7,11 @@
import 'dart:collection';
void main() {
/* Access front of the queue element */
// In Dart, generally use Queue class as queue
/* Initialize the queue */
// In Dart, the deque class Queue is commonly used as a queue
final Queue<int> queue = Queue();
/* Elements enqueue */
/* Enqueue elements */
queue.add(1);
queue.add(3);
queue.add(2);
@@ -19,19 +19,19 @@ void main() {
queue.add(4);
print("Queue queue = $queue");
/* Return list for printing */
/* Access the front element */
final int peek = queue.first;
print("Front element peek = $peek");
/* Element dequeue */
/* Dequeue an element */
final int pop = queue.removeFirst();
print("Dequeue element pop = $pop, after dequeue queue = $queue");
print("Dequeued element pop = $pop; after dequeuing, queue = $queue");
/* Get queue length */
/* Get the queue size */
final int size = queue.length;
print("Queue length size = $size");
print("Queue size = $size");
/* Check if the queue is empty */
/* Check whether the queue is empty */
final bool isEmpty = queue.isEmpty;
print("Is queue empty = $isEmpty");
print("Is the queue empty = $isEmpty");
}

View File

@@ -5,11 +5,11 @@
*/
void main() {
/* Access top of the stack element */
// Dart has no built-in stack class, can use List as stack
/* Initialize the stack */
// Dart has no built-in stack class; a List can be used as a stack
final List<int> stack = [];
/* Elements push onto stack */
/* Push elements onto the stack */
stack.add(1);
stack.add(3);
stack.add(2);
@@ -17,19 +17,19 @@ void main() {
stack.add(4);
print("Stack stack = $stack");
/* Return list for printing */
/* Access the top element */
final int peek = stack.last;
print("Top element peek = $peek");
/* Element pop from stack */
/* Pop an element from the stack */
final int pop = stack.removeLast();
print("Pop element pop = $pop, after pop stack = $stack");
print("Popped element pop = $pop; after popping, stack = $stack");
/* Get the length of the stack */
/* Get the stack size */
final int size = stack.length;
print("Stack length size = $size");
print("Stack size = $size");
/* Check if empty */
/* Check whether it is empty */
final bool isEmpty = stack.isEmpty;
print("Is stack empty = $isEmpty");
print("Is the stack empty = $isEmpty");
}