项目一:数据结构分析与实现。(线性表:实现循环曾链表的基本操作,就是插入,删除,合并)以报告形式写出
项目二实际问题的数据结构分析与实现。如图
编程软件:visualC++6.0
虽然我已编了一个,但觉得不好。可能力有限,希望帮忙。

设计一个简单的程序,有些不懂,希望大家帮帮忙
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
你知我知皆知 2024-08-04 00:54关注以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
这是一个简单的火车订票系统的实现,使用了循环链表来存储列车和乘客信息。在这个系统中,用户可以选择不同的操作,包括录入、查询、订票、退票以及修改车票信息。
首先,我们需要定义一些基本的数据类型:
#include <iostream> using namespace std; struct Passenger { string name; int id; int ticketNum; }; struct Train { int num; int start_time; int end_time; string city; double price; bool is_available; };然后,我们定义一个链表节点类:
class Node { public: Passenger passenger; Node *next; Node(Passenger p) : passenger(p), next(nullptr) {} };接下来,我们定义一个链表类:
class LinkedList { private: Node *head, *tail; public: LinkedList() : head(nullptr), tail(nullptr) {} void insert(int num, int time, string city, double price) { Node *newNode = new Node({num, time, 0, city, price}); if (head == nullptr) { head = newNode; tail = newNode; } else { tail->next = newNode; tail = newNode; } } void remove(int num) { Node *current = head; while (current != nullptr && current->passenger.num != num) { current = current->next; } if (current != nullptr) { if (current->next != nullptr) { current->next = current->next->next; } else { tail = current; } } } void print() const { Node *current = head; while (current != nullptr) { cout << "Passenger: " << current->passenger.name << ", ID: " << current->passenger.id << ", Ticket Number: " << current->passenger.ticketNum << endl; current = current->next; } } };最后,我们创建一个主函数来处理用户的输入并执行相应的操作:
int main() { LinkedList trainList; // 输入列车信息 trainList.insert(1, 8, "上海", 50); trainList.insert(2, 9, "北京", 60); trainList.insert(3, 10, "广州", 70); // 查询列车信息 cout << "请输入列车号进行查询:" << endl; int choice; cin >> choice; trainList.remove(choice); // 订票 cout << "请输入列车号进行订票:" << endl; int trainNum; cin >> trainNum; trainList.insert(trainNum, 11, "杭州", 80); // 退票 cout << "请输入列车号进行退票:" << endl; trainNum = -1; cin >> trainNum; trainList.remove(trainNum); // 修改车票信息 cout << "请输入列车号进行修改:" << endl; trainNum = -1; cin >> trainNum; trainList.print(); return 0; }这个程序只是一个非常基础的实现,没有考虑错误处理和其他复杂情况。在实际应用中,你可能还需要添加更多的功能,例如用户认证、权限管理等。
解决 无用评论 打赏 举报