-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProduct Linked List.py
88 lines (77 loc) · 2.68 KB
/
Product Linked List.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class Node:
def __init__(self, nm, pr, st):
self.name = nm
self.price = pr
self.stock = st
self.ref = None
class Linked_List:
def __init__(self):
self.end = None
self.start = None
self.count = 0
def allProds(self):
itemCount = self.end
while itemCount:
diffName = itemCount.name
diffPrice = itemCount.price
diffStock = itemCount.stock
itemCount = itemCount.ref
print("Name:", diffName, "",
"Price:", diffPrice, "",
"Stock:", diffStock)
def givenPrice(self,certain_price):
itemCount = self.end
while itemCount:
if(itemCount.price > certain_price):
diffName = itemCount.name
diffPrice = itemCount.price
diffStock = itemCount.stock
itemCount = itemCount.ref
print("Name:",diffName, "",
"Price:",diffPrice, "",
"Stock:",diffStock)
else:
itemCount=itemCount.ref
def lowProducts(self):
itemCount = self.end
while itemCount:
if (itemCount.price < 20):
diffName = itemCount.name
diffPrice = itemCount.price
diffStock = itemCount.stock
itemCount = itemCount.ref
print("Name:",diffName, "",
"Price:",diffPrice, "",
"Stock:",diffStock)
else:
itemCount = itemCount.ref
def endItem(self, nm, pr, st):
node = Node(nm, pr, st)
if self.start:
self.start.ref = node
self.start = node
else:
self.end = node
self.start = node
self.count += 1
item = Linked_List()
pick = 0
while pick != 5:
print("\n1. Add product to the list (anywhere)")
print("2. Print all products in the LinkedList")
print("3. Print all products above certain price")
print("4. Print all low-stock products (Less than 20 pounds)")
print("5. Exit")
pick = int(input("\nEnter Your Pick? ==> "))
if(pick == 1):
name=input("Enter Your Name: ")
price=float(input("Enter Your Price: "))
stock=float(input("Enter Your Stock: "))
item.endItem(name,price,stock)
elif(pick == 2):
item.allProds()
elif(pick == 3):
certain_price = float(input("Enter a price to print all items above that amount: "))
item.givenPrice(certain_price)
elif(pick == 4):
item.lowProducts()