Created
October 4, 2020 21:56
-
-
Save n4sm/17cc3350b7921bf2266673b99de6ee80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 4 nsi | |
class Liste: | |
def __init__(self): | |
self.main_l = [0] | |
# =-=-=-=-= Getters =-==-=-=-=-= | |
def ReadElem(self, i): | |
if i > self.main_l[0]: | |
return False | |
return self.main_l[i] | |
def length(self): | |
return self.main_l[0] | |
def isEmpty(self): | |
return self.main_l[0] == 0 | |
# =-=-=-=-= Setters =-==-=-=-=-= | |
def AddElem(self, i, e): | |
if i <= 0 or i > self.main_l[0] + 1: | |
return False | |
if i == 1 and self.isEmpty(): | |
self.main_l.append(e) | |
self.main_l[0] += 1 | |
return self.main_l[i] == e | |
for n in range(self.length()+1, i-1, -1): | |
if n == self.length()+1: | |
self.main_l.append(self.main_l[n-1]) | |
else: | |
self.main_l[n+1] = self.main_l[n] | |
self.main_l[i] = e | |
self.main_l[0] += 1 | |
return self.main_l[i] == e | |
def Edit(self, i, e): | |
if i < 0 or i > self.main_l[0]: | |
return False | |
self.main_l[i] = e | |
return True | |
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | |
def search(self, e): | |
for n in range(self.main_l[0]+1): | |
if self.ReadElem(n) == e: | |
return True | |
return False | |
class Stack: | |
def __init__(self, MaxElem): | |
self.stack = [1] | |
self.max = MaxElem | |
# =-=-=-=-= Getters =-==-=-=-=-= | |
def isEmpty(self): | |
return self.stack[0] == 1 | |
def countElem(self): | |
return self.stack[0]-1 | |
# =-=-=-=-= Setters =-==-=-=-=-= | |
def push(self, e): | |
if self.countElem() == self.max: | |
return False | |
self.stack.append(e) | |
self.stack[0] += 1 | |
return True | |
def pop(self): | |
if self.isEmpty(): | |
return False | |
self.stack[0] -= 1 | |
return self.stack.pop() | |
l = Liste() | |
l.AddElem(1, 1337) | |
l.AddElem(2, l.ReadElem(1)+1) | |
l.AddElem(2, 10) | |
print(l.main_l) | |
print(l.search(1)) | |
s = Stack(20) | |
s.push(1337) | |
s.push(1337) | |
s.push(1337) | |
s.push(1337) | |
for i in range(30): | |
print(s.pop()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment