0% found this document useful (0 votes)
5K views2 pages

IncreasingList Class Implementation

This document defines the IncreasingList class with methods append(), pop(), and __len__() to maintain a list in increasing order. The append() method removes any greater elements and adds the new value to the end. The pop() method removes the last element if the list is not empty. The __len__() method returns the number of elements in the list. The main function opens a file, parses operation names and arguments, and calls the corresponding methods to manipulate an IncreasingList object.

Uploaded by

sach
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5K views2 pages

IncreasingList Class Implementation

This document defines the IncreasingList class with methods append(), pop(), and __len__() to maintain a list in increasing order. The append() method removes any greater elements and adds the new value to the end. The pop() method removes the last element if the list is not empty. The __len__() method returns the number of elements in the list. The main function opens a file, parses operation names and arguments, and calls the corresponding methods to manipulate an IncreasingList object.

Uploaded by

sach
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • IncreasingList Class Definition

import math

import os
import random
import re
import sys

class IncreasingList:
sample=[]

def append(self, val):


"""
first, it removes all elements from the list that have greater values than
val, starting from the last one, and once there are no greater element in the list,
it appends val to the end of the list
"""
if len([Link])==0:
[Link](val)

else:
if val< [Link][-1] and len([Link])!=0:
print([Link][-1])
[Link]()
print("LEngth ",len([Link]))
[Link](val)
else:
[Link](val)

def pop(self):
"""
removes the last element from the list if the list is not empty, otherwise,
if the list is empty, it does nothing
"""
if (len([Link])) !=0:
del [Link][-1]
else:
pass

def __len__(self):
"""
returns the number of elements in the list
"""
return len([Link])
if __name__ == '__main__':
fptr = open("C:\\Users\\Kini\\Desktop\\[Link]", 'r')
lst = IncreasingList()
Lines = [Link]()
for line in Lines:
print("-----------------------")
op = [Link]()
print(op)
op_name = op[0]

if op_name == "append":
val = int(op[1])
[Link](val)
elif op_name == "pop":
[Link]()
elif op_name == "size":
print("%d" % len(lst))
else:
raise ValueError("invalid operation")
print([Link])
[Link]()

import math
import os
import random
import re
import sys
class IncreasingList:
    sample=[]
    def append(self, val):
lst.pop()
        elif op_name == "size":
            print("%d" % len(lst))
        else:
            raise Valu

You might also like