提交 8cb8011a 编写于 作者: W willing0228

Mon Mar 25 11:37:00 CST 2024 inscode

上级 0520122c
import streamlit as st import streamlit as st
from streamlit_option_menu import option_menu import inscode
# 设置Streamlit应用程序的标题 # 数据结构链表类
st.set_page_config(page_title="app name", layout="wide") class LinkedList:
# 节点类
menu1="菜单1" class Node:
menu2="菜单2" def __init__(self, data):
self.data = data
with st.sidebar: self.next = None
menu = option_menu("菜单", [menu1, menu2],
icons=['house', "list-task"], # 初始化链表
menu_icon="cast", default_index=0) def __init__(self):
self.head = None
self.tail = None
self.length = 0
# 添加节点
def add_node(self, data):
node = self.Node(data)
if self.head is None:
self.head = node
self.tail = node
else:
self.tail.next = node
self.tail = node
self.length += 1
# 删除节点
def remove_node(self, data):
if self.head is None:
return
if self.head == self.tail and self.head.data == data:
self.head = None
self.tail = None
self.length -= 1
return
if self.head.data == data:
self.head = self.head.next
self.length -= 1
return
curr_node = self.head.next
prev_node = self.head
while curr_node is not None and curr_node.data != data:
prev_node = curr_node
curr_node = curr_node.next
if curr_node is not None and curr_node.data == data:
prev_node.next = curr_node.next
self.length -= 1
# 查找节点
def find_node(self, data):
curr_node = self.head
while curr_node is not None:
if curr_node.data == data:
return True
curr_node = curr_node.next
return False
# 获取链表长度
def get_length(self):
return self.length
# 获取链表头节点
def get_head(self):
if self.head is not None:
return self.head.data
else:
return None
# 获取链表尾节点
def get_tail(self):
if self.tail is not None:
return self.tail.data
else:
return None
# Streamlit App
def main(): def main():
# Streamlit页面标题
st.title("数据结构链表操作")
# Streamlit页面子标题 - 输入数据生成PPT大纲
st.subheader("输入数据生成PPT大纲")
input_text = st.text_input("请输入内容")
outline = inscode.ai("请根据输入内容,生成链表操作PPT大纲:", input_text)
st.write("生成PPT大纲:")
st.write(outline)
# Streamlit页面子标题 - 链表基本信息展示
st.subheader("链表基本信息展示")
linkedlist = LinkedList()
linkedlist.add_node(1)
linkedlist.add_node(2)
linkedlist.add_node(3)
linkedlist.add_node(4)
linkedlist.add_node(5)
st.write("链表长度为:", linkedlist.get_length())
st.write("链表头节点为:", linkedlist.get_head())
st.write("链表尾节点为:", linkedlist.get_tail())
# Streamlit页面子标题 - 链表操作可视化展示
st.subheader("链表操作可视化展示")
operation = st.selectbox("请选择链表操作", ("", "添加节点", "删除节点", "查找节点"))
if operation == "添加节点":
node_data = st.text_input("请输入节点数据")
if st.button("添加"):
linkedlist.add_node(node_data)
st.write("添加节点:", node_data)
st.write("链表长度:", linkedlist.get_length())
elif operation == "删除节点":
node_data = st.text_input("请输入节点数据")
if st.button("删除"):
linkedlist.remove_node(node_data)
st.write("删除节点:", node_data)
st.write("链表长度:", linkedlist.get_length())
elif operation == "查找节点":
node_data = st.text_input("请输入节点数据")
if st.button("查找"):
if linkedlist.find_node(node_data):
st.write("查找结果:", node_data, "存在于链表中")
else:
st.write("查找结果:", node_data, "不存在于链表中")
if menu == menu1: if __name__ == "__main__":
st.subheader(f"{menu1}") main()
\ No newline at end of file
if menu == menu2:
st.subheader(f"{menu2}")
if __name__ == '__main__':
main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册