-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStackDataList.cs
More file actions
94 lines (82 loc) · 2.32 KB
/
Copy pathStackDataList.cs
File metadata and controls
94 lines (82 loc) · 2.32 KB
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
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace shopManager
{
class Node
{
public Node Next;
public Product Data;
}
public class StackDataList
{
private Node Top;
private int id = 1111110;
public bool IsEmpty()
{
if (Top == null)
return true;
else return false;
}
public void PushNewProduct(string name, string category, int quantity, double cost, double profit)
{
Node prodNode = new Node();
prodNode.Data = new Product(name, category, quantity, id, cost, profit);
prodNode.Next = Top;
Top = prodNode;
id++;
}
public List<Product> GetAllProducts()
{
List<Product> products = new List<Product>();
Node current = Top;
while (current != null)
{
products.Add(current.Data);
current = current.Next;
}
return products;
}
public Product GetSpecificProductById(int id)
{
if (Top == null) return null;
Node p = Top;
if (p.Data.ID == id) return p.Data;
while (p.Next != null)
{
if (p.Next.Data.ID == id)
return p.Next.Data;
p = p.Next;
}
return null;
}
public void RemovedSpesProduct(int id)
{
Node p = Top;
if (p.Data.ID == id)
{
Top = Top.Next;
return;
}
while (p.Next.Data.ID != id)
p = p.Next;
p.Next = p.Next.Next;
}
public void Update(int newQuantity, int id)
{
Node Update = Top;
while (Update != null)
{
if (Update.Data.ID == id)
{
int oldQuantity = Update.Data.Quantity;
Update.Data = new Product(Update.Data.Name, Update.Data.Category, oldQuantity - newQuantity, id, Update.Data.Cost, Update.Data.Profit);
return;
}
Update = Update.Next;
}
}
}
}