Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- laba spiski
- #include<string>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- struct info
- {
- int year=0; string name="" ; int diameter=0, frequency=0;
- info():year(0), name(""), diameter(0), frequency(0) { }
- /* info(info* data) :year(data->year), name(data->name),
- diameter(data->diameter), frequency(data->frequency)*/
- info(info* data) {
- year = data->year;
- name = data->name;
- diameter = data->diameter;
- frequency = data->frequency;
- }
- info(int year, string name, int diameter,int frequency) {
- this->year =year;
- this->name = name;
- this->diameter = diameter;
- this->frequency = frequency;
- }
- };
- struct List {
- info listInfo;
- List* next;
- List* head;
- int size;
- List(): head(nullptr), size(0), next(0){}
- List(info data, List* next = nullptr){
- this->listInfo.year = data.year;
- this->listInfo.name = data.name;
- this->listInfo.diameter = data.diameter;
- this->listInfo.frequency = data.frequency;
- this->next = next;
- }//?
- info& operator [](const int index) {
- List* current(head);
- int counter = 0;
- while (current != nullptr)
- {
- if (counter == index)
- {
- return current->listInfo;
- }
- current = current->next;
- counter++;
- }
- }
- void operator =(const List &list){
- this->listInfo = (list.listInfo);
- // return *this;
- }
- void PushBack(info data){
- if (head == nullptr) {
- head = new List;
- head->listInfo = new info(data);
- }
- else {
- List* temp = this->head;
- while (next) {
- next = temp->next;
- }
- temp->next = new List(data);
- }
- size++;
- }
- List(List* data) {
- List* temp = data->head;
- while (temp != nullptr) {
- this->PushBack(data->listInfo);
- temp = temp->next;
- }
- }
- /* void Sethead(int year, string name, int diameter, int frequency) {
- this->head->listInfo.year = year;
- this->head->listInfo.name = name;
- this->head->listInfo.diameter = diameter;
- this->head->listInfo.frequency = frequency;
- this->head->next = NULL;
- }*/
- /* List* Sortby(int parameter, List* list) { НУЖЕН ИТЕРАТОР
- if (parameter == 1){
- for (int i = n - 1; i >= 0; i--)
- for (int j = 0; j < i; j++)
- if (list->listInfo.name >list->listInfo.name)
- swap(Tables[j], Tables[j + 1]);
- cout << endl;
- print(list);
- }
- }
- }*/
- List* AddList(int year, string name, int diameter, int frequency, List* previous) {
- List* input = new List;
- if (previous==NULL) {
- // Sethead(year, name, diameter, frequency);
- }
- input->listInfo.year = year;
- input->listInfo.name = name;
- input->listInfo.diameter = diameter;
- input->listInfo.frequency = frequency;
- input->next = previous->next;
- previous->next = input;
- return input;
- }
- };
- void print(List* list);
- void AddLast(List **list);
- int main()
- {
- List* list = new List;
- info data;
- data.year = 1955;
- data.name = "Michael Anatolievych";
- data.diameter = 50;
- data.frequency = 12;
- list->PushBack(data);
- info data2(1999, "Storch ", 70, 13);
- list->PushBack(data2);
- List* list2(list);
- print(list2);
- list[1].listInfo.year = 554455;
- print(list);
- return 0;
- }
- void print(List* list) {
- List* Print = list->head;
- cout << "| Year | Name | Diameter | Frequency |\n";
- if (Print)
- while (Print) {
- cout << "|" << setw(7) << Print->listInfo.year << "|" << setw(27) << Print->listInfo.name << "|"
- << setw(11) << Print->listInfo.diameter << "|" << setw(11) << Print->listInfo.frequency << "|\n";
- Print = Print->next;
- }
- else {
Add Comment
Please, Sign In to add comment