CIE Computer Science Linked List Code

*** This is a slightly modified python code from the Cambridge coursebook as the pseudo code provided by the book does not work ***

class ListNode:
    def __init__(self): # object for each node
        self.Data = 0
        self.Pointer = 0
        
class LinkedList:
    def __init__(self,n): # initialisation
        self.__NULLPOINTER = -1
        self.__StartPointer = self.__NULLPOINTER
        self.__FreeListPointer = 0
        self.List = []
        for i in range(n):
            self.List.append(ListNode())
            self.List[i].Pointer = i+1
        self.List[n-1].Pointer = self.__NULLPOINTER

    def display(self): # print a display in order of index position
        print("Start Pointer:", self.__StartPointer)
        print("Free List Pointer:", self.__FreeListPointer)
        print("|{0:^5}|{1:^10}|{2:^10}|".format("Pos", "Data", "Pointer"))
        for i in range(len(self.List)):
            print("|{0:^5}|{1:^10}|{2:^10}|".format(i, self.List[i].Data, self.List[i].Pointer))

    def insert(self,item): # insert item, returns True when inserted and False when set is full
        if self.__FreeListPointer != self.__NULLPOINTER:
            NewNodePointer = self.__FreeListPointer
            self.List[self.__FreeListPointer].Data = item
            self.__FreeListPointer = self.List[self.__FreeListPointer].Pointer
            PreviousPointer = self.__StartPointer
            ThisPointer = self.__StartPointer
            if self.__StartPointer == self.__NULLPOINTER or item < self.List[ThisPointer].Data:
                ThisPointer = self.__StartPointer
                self.List[NewNodePointer].Pointer = ThisPointer
                self.__StartPointer = NewNodePointer
            else:
                HasRun = False
                while self.List[ThisPointer].Data < item and ThisPointer != self.__NULLPOINTER:
                    PreviousPointer = ThisPointer
                    ThisPointer = self.List[ThisPointer].Pointer
                    HasRun = True
                if HasRun:
                    self.List[NewNodePointer].Pointer = self.List[PreviousPointer].Pointer
                    self.List[PreviousPointer].Pointer = NewNodePointer
            return True
        else:
            return False

    def delete(self, item): # delete an item, returns True when deleted and False when not found or set empty
        if self.__StartPointer == self.__NULLPOINTER:
            return False
        if self.List[self.__StartPointer].Data == item:
            self.List[self.__StartPointer].Data = 0
            temp = self.List[self.__StartPointer].Pointer
            self.List[self.__StartPointer].Pointer = self.__FreeListPointer
            self.__FreeListPointer = self.__StartPointer
            self.__StartPointer = temp
        else:
            CurrentNodePtr = self.__StartPointer
            PreviousPtr = -1
            while CurrentNodePtr != self.__NULLPOINTER and self.List[CurrentNodePtr].Data != item:
                PreviousPtr = CurrentNodePtr
                CurrentNodePtr = self.List[CurrentNodePtr].Pointer
            if CurrentNodePtr == self.__NULLPOINTER and self.List[CurrentNodePtr].Data != item:
                return False
            self.List[PreviousPtr].Pointer = self.List[CurrentNodePtr].Pointer
            self.List[CurrentNodePtr].Data = 0
            self.List[CurrentNodePtr].Pointer = self.__FreeListPointer
            self.__FreeListPointer = CurrentNodePtr
            return True

    def find(self, item): # return position of an item, -1 if not found
        CurrentNodePtr = self.__StartPointer
        while CurrentNodePtr != self.__NULLPOINTER and self.List[CurrentNodePtr].Data != item:
            CurrentNodePtr = self.List[CurrentNodePtr].Pointer
        return CurrentNodePtr

    def access(self): # print a display in order of pointers
        CurrentNodePtr = self.__StartPointer
        print("|{0:^10}|{1:^5}|".format("Data","Pos"))
        while CurrentNodePtr != self.__NULLPOINTER:
            print("|{0:^10}|{1:^5}|".format(self.List[CurrentNodePtr].Data, self.List.index(self.List[CurrentNodePtr])))
            CurrentNodePtr = self.List[CurrentNodePtr].Pointer
                    
                
########################
### Example Commands ###
########################

MyLinkList = LinkedList(7)
MyLinkList.display()
MyLinkList.insert(40)
MyLinkList.insert(50)
MyLinkList.insert(10)
MyLinkList.insert(30)
MyLinkList.insert(60)
MyLinkList.insert(70)
MyLinkList.insert(80)
MyLinkList.display()
MyLinkList.access()
MyLinkList.delete(10)
MyLinkList.delete(10)
MyLinkList.delete(30)
MyLinkList.delete(80)
MyLinkList.display()
print("Item found at position", MyLinkList.find(40))
MyLinkList.access()

Advertisements

CIE Computer Science Binary Tree Code

*** This is a slightly modified python code from the Cambridge coursebook as the pseudo code provided by the book does not work ***

class TreeNode: # object for each node
    def __init__(self):
        self.Data = ""
        self.LeftPointer = -1
        self.RightPointer = -1
        
class BinaryTree:
    def __init__(self, n): # initialisation with list length n
        self.null = -1
        self.RootPointer = self.null
        self.FreePointer = 0
        self.Tree = []
        for i in range (0, n):
            self.Tree.append(TreeNode())
            self.Tree[i].LeftPointer = i + 1
        self.Tree[n-1].LeftPointer = self.null

    def display(self): # print a display in order of index positions
        print("{0:^5}|{1:^10}|{2:^10}|{3:^10}|".format("", "Left", "Data", "Right"))
        for i in range (0, len(self.Tree)):
            index = "[" + str(i) + "]"
            print("{0:^5}|{1:^10}|{2:^10}|{3:^10}|".format(index, self.Tree[i].LeftPointer, self.Tree[i].Data, self.Tree[i].RightPointer))
        print("RootPointer:", self.RootPointer)
        print("FreePointer:", self.FreePointer)

    def insert(self, item): # insert item, returns true if inserted and false if set full
        if self.FreePointer == self.null:
            return False
        NewNodePointer = self.FreePointer
        self.FreePointer = self.Tree[self.FreePointer].LeftPointer
        self.Tree[NewNodePointer].Data = item
        self.Tree[NewNodePointer].LeftPointer = self.null
        self.Tree[NewNodePointer].RightPointer = self.null
        if self.RootPointer == self.null:
            self.RootPointer = NewNodePointer
        else:
            ThisNodePointer = self.RootPointer
            while ThisNodePointer != self.null:
                self.PreviousNodePointer = ThisNodePointer
                if self.Tree[ThisNodePointer].Data > item:
                    self.TurnedLeft = True
                    ThisNodePointer = self.Tree[ThisNodePointer].LeftPointer
                else:
                    self.TurnedLeft = False
                    ThisNodePointer = self.Tree[ThisNodePointer].RightPointer
            if self.TurnedLeft:
                self.Tree[self.PreviousNodePointer].LeftPointer = NewNodePointer
            else:
                self.Tree[self.PreviousNodePointer].RightPointer = NewNodePointer
        return True

    def find(self, item): # returns position of an item, -1 if not found
        ThisNodePointer = self.RootPointer
        while ThisNodePointer != self.null and self.Tree[ThisNodePointer].Data != item:
            if self.Tree[ThisNodePointer].Data > item:
                ThisNodePointer = self.Tree[ThisNodePointer].LeftPointer
            else:
                ThisNodePointer = self.Tree[ThisNodePointer].RightPointer
        return ThisNodePointer

#######################
## Examples commands ##
#######################
    
MyTree = BinaryTree(6) # Create a tree of length 6
MyTree.display() # display tree in a table
MyTree.insert(10) # insert number 10
MyTree.insert(40)
MyTree.insert(30)
MyTree.insert(50)
MyTree.insert(60)
MyTree.display()
print("Item found at position", MyTree.find(30)) # print the position of number 30

(unfinished) A Guide to Yes Albums by Line-ups

Yes is an English progressive rock band that has been active since 1968 with two hiatus in the 80’s and 2000’s. Progressive rock bands were known for frequent line-up changes, and Yes was no exception. Here is a guide to Yes albums, by famous line-ups.

*********** Anderson, Bruford, Howe, Kaye, Squire (1970 – 1971) ************

This is a short lived line-up of Yes, with Steve Howe replacing the original guitarist Peter Banks and the rest of the band remaining the same. This line-up spanned a duration of one year and one album.

>>>> The Yes Album

Yes_Album_Front^Must-heard^ “The Yes Album” is the third studio album and the first featuring guitarist Steve Howe. It is defining album that shaped the future musical format and style of Yes.

The addition of Howe on guitar added another dimension to the musicality of Yes. His versatility and ability to change his playing style lead to a sonic exploration – with tracks containing both jangly and smooth jazzy tone on the electric guitar (“Yours is no Disgrace”), upbeat steel string acoustic guitar (“Clap”), and exotic Portuguese guitar (“I’ve Seen All Good People”).

Chris Squire really started to shine on this album with his signature melodic and trebly bassline. He turned the bass guitar into a lead instrument, much like what John Entwistle of The Who did, instead of a sheer background instrument thay lays down the lower frequencies in the band mix.

Tony Kaye’s hammond organ playing continues to drive the tracks, taking both the roles of creating melodic lines and laying down chord blocks. Bill Bruford’s jazz influence really starts to show in this album with frequent uses triplets and the high hat, adding jazzy vamps to songs. His accuracy with drum fills and timing also tightens the tracks.

The band’s fantastic vocal harmony is further proven with tracks like the impossibly catchy “I’ve Seen All Good People”. The combination of Jon Anderson’s heavenly vocals and Squire and Howe’s deeper voices works fabulously well. This really gives the band a fuller and much more harmonious sound which later developes into an almost orchestral orientation.

Interesting tracks: ALL

*********** Anderson, Banks, Bruford, Kaye, Squire (1968 – 1970) ************

The band recorded two albums with the orignal line-up consisted of Jon Anderson on vocals, Peter Banks on guitar, Bill Bruford on drums, Chris Squire on bass, and Tony Kaye on piano and organ.

>>>> Yes


122767_f_1^Recommended^ The self titled debut album “Yes” is a very
decent debut album that gives a glimpse to the early stage of the band. The sound that later characterized Yes can be heard all over the album, including frequent uses of vocal harmony, trebly bass guitar, keyboard driven tracks, and so on.

Something worth noting is the guitar solo in “I See You”. Bill Bruford played the high hat from around 3:00 to 4:53, and the wah-wah guitar solo phrases come in at 4:53 with each phrase following two drum beats. Almost identical to that of “Whole Lotta Love” by Led Zeppelin…

Interesting tracks: “Beyond and Before”, “I See You”, “Survival”

ed13d487e85d09bfd1e1e2daa524c8dc
Source: https://en.wikipedia.org/wiki/List_of_Yes_band_members