Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
/pythonPublic archive

New Algorithm#155

Open
guruprashanth2004 wants to merge1 commit intoAllAlgorithms:master
base:master
Choose a base branch
Loading
fromguruprashanth2004:master
Open
Changes fromall 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
32 changes: 32 additions & 0 deletionsdata-structures/Stack/StackImplementation.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@

from sys import maxsize

def createStack():
stack = []
return stack

def isEmpty(stack):
return len(stack) == 0

def push(stack, item):
stack.append(item)
print(item + " pushed to stack ")

# Function to remove an item from stack. It decreases size by 1
def pop(stack):
if (isEmpty(stack)):
return str(-maxsize -1) # return minus infinite

return stack.pop()

# Function to return the top from stack without removing it
def peek(stack):
if (isEmpty(stack)):
return str(-maxsize -1) # return minus infinite
return stack[len(stack) - 1]

stack = createStack()
push(stack, str(10))
push(stack, str(20))
push(stack, str(30))
print(pop(stack) + " popped from stack")

[8]ページ先頭

©2009-2025 Movatter.jp