Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
54 changes: 0 additions & 54 deletions Exercise_1.cpp
Original file line number Diff line number Diff line change
@@ -1,54 +0,0 @@
#include <bits/stdc++.h>

using namespace std;

#define MAX 1000

class Stack {
//Please read sample.java file before starting.
//Kindly include Time and Space complexity at top of each file
int top;

public:
int a[MAX]; // Maximum size of Stack

Stack() { //Constructor here }
bool push(int x);
int pop();
int peek();
bool isEmpty();
};

bool Stack::push(int x)
{
//Your code here
//Check Stack overflow as well
}

int Stack::pop()
{
//Your code here
//Check Stack Underflow as well
}
int Stack::peek()
{
//Your code here
//Check empty condition too
}

bool Stack::isEmpty()
{
//Your code here
}

// Driver program to test above functions
int main()
{
class Stack s;
s.push(10);
s.push(20);
s.push(30);
cout << s.pop() << " Popped from stack\n";

return 0;
}
46 changes: 0 additions & 46 deletions Exercise_1.java
Original file line number Diff line number Diff line change
@@ -1,46 +0,0 @@
class Stack {
//Please read sample.java file before starting.
//Kindly include Time and Space complexity at top of each file
static final int MAX = 1000;
int top;
int a[] = new int[MAX]; // Maximum size of Stack

boolean isEmpty()
{
//Write your code here
}

Stack()
{
//Initialize your constructor
}

boolean push(int x)
{
//Check for stack Overflow
//Write your code here
}

int pop()
{
//If empty return 0 and print " Stack Underflow"
//Write your code here
}

int peek()
{
//Write your code here
}
}

// Driver code
class Main {
public static void main(String args[])
{
Stack s = new Stack();
s.push(10);
s.push(20);
s.push(30);
System.out.println(s.pop() + " Popped from stack");
}
}
35 changes: 0 additions & 35 deletions Exercise_1.js
Original file line number Diff line number Diff line change
@@ -1,35 +0,0 @@
class Stack {
//Please read sample.java file before starting.
//Kindly include Time and Space complexity at top of each file
constructor() {
//Initialize your constructor
this.MAX = 1000;
this.top = -1;
this.a = new Array(this.MAX);
}
function isEmpty() {
//Write your code here
}
function push(x) {
//Check for stack Overflow
//Write your code here
}
function pop() {
//If empty return 0 and print " Stack Underflow"
//Write your code here
}
function peek() {
//Write your code here
}
}
let s = new Stack();
s.push(10);
s.push(20);
s.push(30);
console.log(s.pop() + " Popped from stack");
26 changes: 18 additions & 8 deletions Exercise_1.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
class myStack:
#Please read sample.java file before starting.
#Kindly include Time and Space complexity at top of each file
def __init__(self):

time :0(1)
space:0(n)
def __init__(self):
self.stack = []
def isEmpty(self):

return len(self.stack) == 0
def push(self, item):

self.stack.append(item)
def pop(self):

if self.isEmpty():
print("Stack Underflow")
return None
return self.stack.pop()

def peek(self):

if self.isEmpty():
print("Stack is Empty")
return None
return self.stack[-1]
def size(self):

return len(self.stack)
def show(self):

return self.stack



s = myStack()
s.push('1')
Expand Down
52 changes: 0 additions & 52 deletions Exercise_2.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +0,0 @@
#include <bits/stdc++.h>
using namespace std;

// A structure to represent a stack
class StackNode {
public:
int data;
StackNode* next;
};

StackNode* newNode(int data)
{
StackNode* stackNode = new StackNode();
stackNode->data = data;
stackNode->next = NULL;
return stackNode;
}

int isEmpty(StackNode* root)
{
//Your code here
}

void push(StackNode** root, int data)
{
//Your code here
}

int pop(StackNode** root)
{
//Your code here
}

int peek(StackNode* root)
{
//Your code here
}

int main()
{
StackNode* root = NULL;

push(&root, 10);
push(&root, 20);
push(&root, 30);

cout << pop(&root) << " popped from stack\n";

cout << "Top element is " << peek(root) << endl;

return 0;
}
52 changes: 0 additions & 52 deletions Exercise_2.java
Original file line number Diff line number Diff line change
@@ -1,52 +0,0 @@
public class StackAsLinkedList {

StackNode root;

static class StackNode {
int data;
StackNode next;

StackNode(int data)
{
//Constructor here
}
}


public boolean isEmpty()
{
//Write your code here for the condition if stack is empty.
}

public void push(int data)
{
//Write code to push data to the stack.
}

public int pop()
{
//If Stack Empty Return 0 and print "Stack Underflow"
//Write code to pop the topmost element of stack.
//Also return the popped element
}

public int peek()
{
//Write code to just return the topmost element without removing it.
}

//Driver code
public static void main(String[] args)
{

StackAsLinkedList sll = new StackAsLinkedList();

sll.push(10);
sll.push(20);
sll.push(30);

System.out.println(sll.pop() + " popped from stack");

System.out.println("Top element is " + sll.peek());
}
}
36 changes: 0 additions & 36 deletions Exercise_2.js
Original file line number Diff line number Diff line change
@@ -1,36 +0,0 @@
class StackAsLinkedList {
static stackNode = class {
constructor(d) {
//Constructor here
this.data = d;
this.next = null;
}
}
function isEmpty() {
//Write your code here for the condition if stack is empty.
}
function push(data) {
//Write code to push data to the stack.
}
function pop() {
//If Stack Empty Return 0 and print "Stack Underflow"
//Write code to pop the topmost element of stack.
//Also return the popped element
}
function peek() {
//Write code to just return the topmost element without removing it.
}
}
//Driver code
const sll = new StackAsLinkedList();
sll.push(10);
sll.push(20);
sll.push(30);
console.log(sll.pop() + " popped from stack");
console.log("Top element is " + sll.peek());
14 changes: 11 additions & 3 deletions Exercise_2.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@

/time 0(1)
/space 0(n)
class Node:
def __init__(self, data):
self.data = data
self.next = None

class Stack:
def __init__(self):

self.top = None
def push(self, data):

new_node = Node(data)
new_node.next = self.top
self.top = new_node
def pop(self):
if self.top is None:
return None
popped_value = self.top.data
self.top = self.top.next
return popped_val

a_stack = Stack()
while True:
Expand Down
Loading