链表式学生成绩管理系统
时间: 2023-12-05 17:05:12 浏览: 108
链表实现学生成绩管理系统.doc
链表式学生成绩管理系统是一种基于链表数据结构的学生成绩管理系统。其主要设计思路是将每个学生的信息存储在一个节点中,通过节点之间的指针连接形成链表。这种设计思路具有以下优点:
1.插入、删除、修改操作方便:由于链表的特性,插入、删除、修改操作只需要改变相应节点的指针即可,不需要移动其他节点,因此效率较高。
2.空间利用率高:链表中每个节点只需要存储当前学生的信息和指向下一个节点的指针,不需要预留一定的空间,因此空间利用率较高。
3.支持动态扩展:由于链表的特性,可以动态地添加或删除节点,因此支持动态扩展。
下面是链表式学生成绩管理系统的基本功能模块:
1.数据插入模块:将学生的信息插入到链表中。
2.数据修改模块:修改链表中某个学生的信息。
3.数据删除模块:删除链表中某个学生的信息。
4.成绩登记模块:为某个学生登记成绩。
5.成绩修改模块:修改某个学生的成绩。
6.数据浏览模块:浏览链表中所有学生的信息。
7.成绩统计模块:统计每个学生的总分及平均分并能根据学生的平均成绩排序。
8.成绩表查看模块:输出学生成绩单。
下面是一个简单的Python实现链表式学生成绩管理系统的例子:
```python
class Node:
def __init__(self, name, score):
self.name = name
self.score = score
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def insert(self, name, score):
new_node = Node(name, score)
if self.head is None:
self.head = new_node
else:
current = self.head
while current.next is not None:
current = current.next
current.next = new_node
def search(self, name):
current = self.head
while current is not None:
if current.name == name:
return current
current = current.next
return None
def delete(self, name):
current = self.head
previous = None
while current is not None:
if current.name == name:
if previous is None:
self.head = current.next
else:
previous.next = current.next
return True
previous = current
current = current.next
return False
def update(self, name, score):
current = self.search(name)
if current is not None:
current.score = score
return True
else:
return False
def display(self):
current = self.head
while current is not None:
print(current.name, current.score)
current = current.next
def sort(self):
if self.head is None:
return
else:
current = self.head
while current.next is not None:
next_node = current.next
while next_node is not None:
if current.score > next_node.score:
temp = current.score
current.score = next_node.score
next_node.score = temp
temp = current.name
current.name = next_node.name
next_node.name = temp
next_node = next_node.next
current = current.next
def statistics(self):
current = self.head
while current is not None:
total = 0
count = 0
current_score = current
while current_score is not None and current_score.name == current.name:
total += current_score.score
count += 1
current_score = current_score.next
print(current.name, "total score:", total, "average score:", total / count)
current = current_score
def output(self):
current = self.head
while current is not None:
print(current.name, current.score)
current = current.next
linked_list = LinkedList()
linked_list.insert("Tom", 80)
linked_list.insert("Jerry", 90)
linked_list.insert("Lucy", 85)
linked_list.insert("John", 95)
linked_list.display()
linked_list.sort()
linked_list.display()
linked_list.statistics()
linked_list.output()
```
阅读全文