class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[-1]
stack = Stack()
stack.push(10)
stack.push("Hello")
class Stack {
constructor() {
this.items = [];
}
push(element) {
this.items.push(element);
}
pop() {
return this.items.pop();
}
peek() {
return this.items[this.items.length - 1];
}
}
const stack = new Stack();
stack.push(10);
stack.push("Hello");
#include <stack>
#include <iostream>
using namespace std;
int main() {
stack<string> s;
s.push("10");
s.push("Hello");
cout << s.top() << endl;
s.pop();
return 0;
}
#include <stdio.h>
#define MAX 100
typedef struct {
char items[MAX][50];
int top;
} Stack;
void push(Stack* s, char* item) {
s->items[++s->top] = item;
}
char* pop(Stack* s) {
return s->items[s->top--];
}
int main() {
Stack s = {.top = -1};
push(&s, "10");
push(&s, "Hello");
return 0;
}