示例#1
0
def reverse_linkedlist(reverse_list):
    #write your logic here
    list1 = []
    new_list = LinkedList()
    temp = reverse_list.get_head()
    while(temp is not None):
        list1.append(temp.get_data())
        temp = temp.get_next()
    reverse_list = list1[::-1]
    for i in range(0,len(reverse_list)):
        new_list.add(reverse_list[i])
    reverse_list = new_list   
    return reverse_list
示例#2
0
 def __init__(self):
     self.__occupied_table_list = LinkedList()
示例#3
0
def remove_duplicates(duplicate_list):
    list1 = []
    temp = duplicate_list.get_head()
    while temp is not None:
        list1.append(temp.get_data())
        temp = temp.get_next()
    a = set(list1)
    b = list(a)
    b.sort()
    temp = duplicate_list.get_head()
    while temp is not None:
        duplicate_list.delete(temp.get_data())
        temp = temp.get_next()

    for i in b:
        duplicate_list.add(i)
    #write your logic here
    return duplicate_list


#Add different values to the linked list and test your program
duplicate_list = LinkedList()
duplicate_list.add(30)
duplicate_list.add(40)
duplicate_list.add(40)
duplicate_list.add(40)
duplicate_list.add(40)

remove_duplicates(duplicate_list)
示例#4
0
def reverse_linkedlist(reverse_list):
    list1 = []
    temp = reverse_list.get_head()
    while temp is not None:
        list1.append(temp.get_data())
        temp = temp.get_next()

    list1.reverse()

    temp = reverse_list.get_head()
    while temp is not None:
        reverse_list.delete(temp.get_data())
        temp = temp.get_next()

    for i in list1:
        reverse_list.add(i)
    #write your logic here
    return reverse_list


#Add different values to the linked list and test your program
reverse_list = LinkedList()
reverse_list.add(10)
reverse_list.add(15)
reverse_list.add(14)
reverse_list.add(28)
reverse_list.add(30)
reversed_linkedlist = reverse_linkedlist(reverse_list)
reversed_linkedlist.display()
示例#5
0
    # Write your logic here
    temp = word_list.get_head()
    while (temp is not None):
        new = temp.get_data()
        if (new == "*" or new == "/"):
            new_sentence += " "
        elif (new_sentence[-2:] == "  "):
            new_sentence += new.upper()
        else:
            new_sentence += new
        temp = temp.get_next()
    new_sentence = new_sentence.replace('  ', ' ')
    return new_sentence


word_list = LinkedList()
word_list.add("T")
word_list.add("h")
word_list.add("e")
word_list.add("/")
word_list.add("*")
word_list.add("s")
word_list.add("k")
word_list.add("y")
word_list.add("*")
word_list.add("i")
word_list.add("s")
word_list.add("/")
word_list.add("/")
word_list.add("b")
word_list.add("l")
示例#6
0
        while (temp is not None):
            list1.append(temp.get_data())
            temp = temp.get_next()
        for i in range(0, len(list1)):
            vacant_seat_list.append(list1[i].get_total_seats() -
                                    list1[i].get_no_of_passengers())
            if (vacant_seat_list[i] > (list1[i].get_total_seats()) / 2):
                count += 1
        return count

    #Implement the remaining methods of Train class here


#Use different values for compartment and test your program
compartment1 = Compartment("SL", 250, 400)
compartment2 = Compartment("2AC", 125, 280)
compartment3 = Compartment("3AC", 120, 300)
compartment4 = Compartment("FC", 160, 300)
compartment5 = Compartment("1AC", 100, 210)
compartment_list = LinkedList()
compartment_list.add(compartment1)
compartment_list.add(compartment2)
compartment_list.add(compartment3)
compartment_list.add(compartment4)
compartment_list.add(compartment5)
train1 = Train("Shatabdi", compartment_list)
count = train1.count_compartments()
print("The number of compartments in the train:", count)
vacancy_count = train1.check_vacancy()
print("The number of compartments which have more than 50% vacancy:",
      vacancy_count)
示例#7
0
            before_child = before_child.get_next()
            count -= 1
        self.__children_list.insert(child, before_child.get_data())

    def add_new_child(self, child):
        self.__children_list.add(child)


child1 = Child("Rahul", "solo song")
child2 = Child("Sheema", "Dance")
child3 = Child("Gitu", "Plays Flute")
child4 = Child("Tarun", "Gymnastics")
child5 = Child("Tom", "MIME")

#Add different values to the list and test the program
children_list = LinkedList()
children_list.add(child1)
children_list.add(child2)
children_list.add(child3)
children_list.add(child4)
children_list.add(child5)
performance = Performance(children_list)
print("The order in which the children would perform:")
performance.get_children_list().display()
print()
print("After Rahul's performance, the schedule would change to:")
performance.change_position(child1)
performance.get_children_list().display()
print()
child6 = Child("Swetha", "Vote of Thanks")
print("After Swetha has joined, the schedule is:")