---
# System prepended metadata

title: Case Study - Set Implement
tags: [DSA, OOP, Class]

---

# Case Study - Set Implement
###### tags: `Class` `OOP` `DSA`

## Case1: Implemented by linked-list
> [name=Jason Lin]
```python=
class node:
    def __init__(self,n=None):
        self.__next=None
        self.__value=n
    def setVal(self,n):
        self.__value=n
    def setNext(self,nextnode):
        self.__next=nextnode
    def getVal(self):
        return self.__value
    def getNext(self):
        return self.__next

class myset:
    def __init__(self):
        self.__count=0
        self.__head=node()
    def len(self):
        return self.__count
    def ist(self,n):
        if self.mem(n): return False
        if self.__count==0:
            self.__head.setVal(n)
        else:
            nod = node(n)
            nod.setNext(self.__head)
            self.__head=nod
        self.__count+=1
        return True
    def dlt(self,n):
        if not self.mem(n): return False
        self.__count-=1
        nod=self.__head
        if nod.getVal()==n:
            self.__head=nod.getNext()
            return True
        while nod.getNext()!=None:
            if nod.getNext().getVal()==n:
                nod.setNext(nod.getNext().getNext())
                return True
            nod=nod.getNext()
    def mem(self,n):
        nod=self.__head
        while nod!=None:
            if nod.getVal()==n: return True
            nod=nod.getNext()
        return False
    def max(self):
        maxVal=float('-inf')
        nod=self.__head
        while nod.getNext()!=None:
            if nod.getVal()>maxVal: maxVal=nod.getVal() 
            nod=nod.getNext()
        return maxVal
#unit test
if __name__=='__main__':
    mineset=myset()
    print('len=',mineset.len())
    mineset.ist(3)
    mineset.ist(0)
    mineset.ist(3)
    mineset.ist(0)
    mineset.ist(2)
    mineset.ist(6)
    print('max=',mineset.max())
    print('len=',mineset.len())
    print('is 30 in?',mineset.mem(30))
    print('is 3 in?',mineset.mem(3))
    mineset.dlt(3)
    print('is 3 in?',mineset.mem(3))
    mineset.dlt(6)
    print('max=',mineset.max())
    print('len=',mineset.len())
```