基于python链表实现个人资产管理系统
时间: 2024-01-04 07:48:35 浏览: 68
基于Python实现的资产管理系统
5星 · 资源好评率100%
首先,我们需要定义一个节点类来表示链表中的每个节点:
```python
class Node:
def __init__(self, date, income, expense):
self.date = date
self.income = income
self.expense = expense
self.next = None
```
接下来,我们定义一个链表类来管理节点:
```python
class LinkedList:
def __init__(self):
self.head = None
def add_node(self, date, income, expense):
new_node = Node(date, income, expense)
if not self.head:
self.head = new_node
else:
current = self.head
while current.next:
current = current.next
current.next = new_node
def show_list(self):
current = self.head
while current:
print(f"Date: {current.date}, Income: {current.income}, Expense: {current.expense}")
current = current.next
```
现在,我们可以创建一个链表对象并添加节点:
```python
linked_list = LinkedList()
linked_list.add_node("2022-01-01", 1000, 500)
linked_list.add_node("2022-01-02", 1500, 800)
linked_list.add_node("2022-01-03", 2000, 1000)
linked_list.show_list()
```
输出:
```
Date: 2022-01-01, Income: 1000, Expense: 500
Date: 2022-01-02, Income: 1500, Expense: 800
Date: 2022-01-03, Income: 2000, Expense: 1000
```
接下来,我们可以添加其他方法来实现个人资产管理系统,例如计算总收入、总支出、净收入等。
阅读全文