School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,46 @@
from Bag import Bag, BagIterator
def createIntBag():
intBag=Bag()
intBag.add(6)
intBag.add(11)
intBag.add(77)
intBag.add(7)
intBag.add(4)
intBag.add(6)
intBag.add(77)
intBag.add(6)
return intBag
def createStringBag():
stringBag=Bag()
stringBag.add("data")
stringBag.add("structures")
stringBag.add("and")
stringBag.add("algorithms")
stringBag.add("data")
stringBag.add("data")
stringBag.add("algorithms")
return stringBag
def printBag(bag):
it = bag.iterator()
while it.valid():
print(it.getCurrent())
it.next()
print("Over. Let's start again.")
it.first()
while it.valid():
print(it.getCurrent())
it.next()
def main():
b1 = createIntBag()
printBag(b1)
print("No occurrences of 77: ", b1.nrOccurrences(77))
b2 = createStringBag()
printBag(b2)
print("No occurrences of 'data': ", b2.nrOccurrences("data"))
if __name__ == "__main__":
main()