Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <Windows.h>
- using namespace std;
- struct BusInfo {
- int routeNum;
- string minute, hour, day, month, year;
- double cost;
- };
- struct Node
- {
- string busNum;
- BusInfo info;
- Node* prev;
- Node* next;
- };
- BusInfo createBus() {
- BusInfo info;
- cout << "Введите номер маршрута: ";
- cin >> info.routeNum;
- cout << "Введите дату отправления в формате дд.мм.гггг: ";
- string date;
- cin >> date;
- info.day = date.substr(0, 2);
- info.month = date.substr(3, 2);
- info.year = date.substr(6, 4);
- cout << "Введите время отправления в формате чч:мм: ";
- string time;
- cin >> time;
- info.hour = time.substr(0, 2);
- info.minute = time.substr(3, 2);
- cout << "Введите цену поездки: ";
- cin >> info.cost;
- return info;
- }
- void printNodeWithLabel(Node* cur) {
- cout << "Номер автобуса: " << cur->busNum << " Маршрут: " << cur->info.routeNum << " Дата отправления: "
- << cur->info.day << "." << cur->info.month << "." << cur->info.year << " Время отправления: "
- << cur->info.hour << ":" << cur->info.minute << " Цена поездки: " << cur->info.cost << "р" << endl;
- }
- void printNode(Node* cur) {
- cout << cur->busNum << "\t\t\t" << cur->info.routeNum << "\t\t"
- << cur->info.day << "." << cur->info.month << "." << cur->info.year << "\t\t"
- << cur->info.hour << ":" << cur->info.minute << "\t\t\t" << cur->info.cost << "р" << endl;
- }
- void printList(Node* head) {
- Node* current = head;
- if (head != NULL) {
- cout << "Номер автобуса:\t\t" << "Маршрут:\t" << "Дата отправления:\t"
- << "Время отправления:\t" << "Цена поездки:\t" << endl;
- }
- while (current != NULL) {
- printNode(current);
- current = current->next;
- }
- cout << endl;
- }
- void printReverseList(Node* tail) {
- Node* current = tail;
- while (current != NULL) {
- printNode(current);
- current = current->prev;
- }
- cout << endl;
- }
- void addAtFront(Node*& head, Node*& tail, string busNum, BusInfo info) {
- if (head == NULL && tail == NULL)
- {
- Node* temp = new Node;
- temp->busNum = busNum;
- temp->info = info;
- temp->next = NULL;
- temp->prev = NULL;
- head = temp;
- tail = temp;
- }
- else
- {
- Node* temp = new Node;
- temp->busNum = busNum;
- temp->info = info;
- temp->next = head;
- temp->prev = NULL;
- head->prev = temp;
- head = temp;
- }
- }
- void addAtBack(Node*& head, Node*& tail, string busNum, BusInfo info) {
- if (head == NULL && tail == NULL)
- {
- Node* temp = new Node;
- temp->busNum = busNum;
- temp->info = info;
- temp->next = NULL;
- temp->prev = NULL;
- head = temp;
- tail = temp;
- }
- else
- {
- Node* temp = new Node;
- temp->busNum = busNum;
- temp->info = info;
- temp->prev = tail;
- temp->next = NULL;
- tail->next = temp;
- tail = temp;
- }
- }
- void createList(Node*& head, Node*& tail, int n) {
- for (int i = 0; i < n; i++) {
- string busNum;
- BusInfo info;
- cout << "Введите номер автобуса: ";
- cin >> busNum;
- addAtBack(head, tail, busNum, createBus());
- cout << endl;
- }
- }
- void addAfterLastWithValue(Node*& tail, string busNum) {
- Node* elem = tail;
- while (elem != NULL) {
- if (elem->busNum == busNum) {
- Node* newNode = new Node;
- cout << "Введите номер автобуса: ";
- cin >> newNode->busNum;
- newNode->info = createBus();
- cout << endl;
- newNode->next = elem->next;
- newNode->prev = elem;
- elem->next->prev = newNode;
- elem->next = newNode;
- break;
- }
- elem = elem->prev;
- }
- }
- void delAllWithValue(Node*& head, string busNum) {
- Node* elem = head;
- while (elem != NULL) {
- if (elem->busNum == busNum) {
- elem->prev->next = elem->next;
- elem->next->prev = elem->prev;
- }
- elem = elem->next;
- }
- }
- int countWithValue(Node* head, string busNum, string date) {
- Node* elem = head;
- int count = 0;
- string day = date.substr(0, 2);
- string month = date.substr(3, 2);
- string year = date.substr(6, 4);
- while (elem != NULL) {
- if (elem->busNum == busNum && elem->info.day == day && elem->info.month == month && elem->info.year == year) {
- count++;
- }
- elem = elem->next;
- }
- return count;
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- Node* head = NULL;
- Node* tail = NULL;
- int num;
- cout << "Введите количество рейсов, которое вы хотите заполнить: ";
- cin >> num;
- createList(head, tail, num);
- printList(head);
- string value;
- cout << "Введите номер автобуса, после последней записи которого хотите добавить новый рейс: ";
- cin >> value;
- addAfterLastWithValue(tail, value);
- printList(head);
- cout << "Введите номер автобуса, все записи которого хотите удалить: ";
- cin >> value;
- delAllWithValue(head, value);
- printList(head);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement