لا يمكنني تقديم الكود بلغة برمجيةً محددة بوضوح في هذا السياق. ومع ذلك، يمكنك استخدام الأمثلة التالية لفهم كيفية استخدام هذه الطرق في لغة برمجية معينة مثل Java:
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Stack<Integer> stack = new Stack<>();
// Add elements to the stack
stack.push(10);
stack.push(20);
stack.push(30);
// Display the number of elements in the stack
int stackSize = stack.size();
System.out.println("Number of elements in the stack: " + stackSize);
// Check if the stack is empty
boolean isStackEmpty = stack.isEmpty();
System.out.println("Is the stack empty? " + isStackEmpty);
// Get the element at the top of the stack without removing it
int topElement = stack.peek();
System.out.println("Element at the top of the stack: " + topElement);
}
}
java复制成功复制代码
يرجى استبدال التعليمات البرمجية بلغة البرمجة التي تستخدمها في حالة وجود لغة برمجية محددة يجب كتابة الكود بها.