+ 2

I need help. I want to print data in list in c++. First i inserted some information into the list and don't know to print them

class List1{ public: Park info; List1* next; }; List1* last = NULL; List1* head = NULL; List1* potr = NULL; for(int i =0; i<3; i++){ if(head==0){ cout<<"Ro'yxat bo'sh"<<endl; continue; } cout<<"******Ro'yxat*******"<<endl<<endl; potr[i] = head[i]; while(1){ cout<<potr[i].info<<endl; if(potr[i].next ==0) break; potr[i] = potr[i].next; } cout<<endl; continue; } Here 'potr[i] = potr[i].next' is giving an error. What should I do?

25th Nov 2020, 7:49 PM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
23 Antworten
+ 3
Where is definition of `Park` in class `List1`? Park info; // <-- Undefined Park
25th Nov 2020, 10:54 PM
Ipang
+ 2
Fayzullo Abduhakimov You need to save your code in SoloLearn first. Then share just the saved code link here. That way you don't have to worry your code get truncated because it's too big. Just follow the below guide 👇 https://www.sololearn.com/post/75089/?ref=app
26th Nov 2020, 4:39 AM
Ipang
+ 2
Ok thanks 😊 for attention
27th Nov 2020, 6:45 PM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
+ 1
Try potr[i]->next The dot is used to acces a member of a structure. The arrow is used to access a member of a structure through a pointer to that structure. if potr[i] is a pointer to a structure you have to use the arrow
25th Nov 2020, 8:34 PM
Davide
Davide - avatar
27th Nov 2020, 9:27 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
It's from data-structures. I mustn't use 'list'
26th Nov 2020, 3:51 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
#include <iostream> #include <sstream> using namespace std; class Park { public: int nomeri; string FIO; int yonalish_nomeri; string Strings; void kirit(int number, string FIO, int yo_nomer){ this->nomeri = number; this->FIO = FIO; this->yonalish_nomeri = yo_nomer; } void chiqar(){ cout<<"Nomeri: "<<nomeri<<endl; cout<<"FIO: "<<FIO<<endl; cout<<"Yo'nalish nomeri': "<<yonalish_nomeri<<endl; } operator const char*(){ ostringstream formatting; formatting<<nomeri<<endl; formatting<<FIO<<endl; formatting<<yonalish_nomeri<<endl; Strings = formatting.str(); return Strings.c_str(); } }; class List1{ public: Park info; List1* next; }; class List2{ public: Park info; List2* next; }; List1* lst=NULL; List1* last = NULL; List1* head = NULL; List1* potr = NULL; int main(){ Park car[3]; car[0].kirit(321,"Abdullayev Abdulla", 56); car[1].kirit(743,"Sobirov Jamshid", 87); c
26th Nov 2020, 4:33 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
int main(){ Park car[3]; car[0].kirit(321,"Abdullayev Abdulla", 56); car[1].kirit(743,"Sobirov Jamshid", 87); car[2].kirit(823,"Nosirov Elyor", 70); List1* p = new List1[3]; for(int i=0; i<3; i++){ p[i].info = car[i]; p[i].next = NULL; if(lst==NULL){ *lst = p[i]; *last = p[i]; } else{ last->next = &p[i]; last = &p[i]; } } for(int i =0; i<3; i++){ if(head==0){ cout<<"Ro'yxat bo'sh"<<endl; continue; }
26th Nov 2020, 4:36 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
I couldn't send full code at once
26th Nov 2020, 4:36 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
Words were limited
26th Nov 2020, 4:37 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
Ok. Can anybody help me solve this problem?
26th Nov 2020, 6:26 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
Fayzullo Abduhakimov as Ipang said, you need to share your code properly. Like that https://code.sololearn.com/csruO5TPQa14/?ref=app Just copy/paste your code in the playground and then share it with the '+" button that you can see while writing a comment. You'll find your code in your code bits
26th Nov 2020, 11:02 AM
Davide
Davide - avatar
0
I think i managed to send the code. And now please help what to do
27th Nov 2020, 9:27 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
I should insert all data into the linear list and then print them all.
27th Nov 2020, 9:29 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
And also give advice how to remove a data in the list if possible
27th Nov 2020, 9:30 AM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
I need help!
27th Nov 2020, 1:02 PM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
in line 90 potr[i] = potr[i]->next; Since potr[i] is not a pointer, it was right to use the dot instead of the arrow. However potr[i].next is a pointer and you can't assign it to potr[i] I have no idea of what the program does. If your intentions were to assign to potr[i] what is pointed by potr[i].next, you can do it in this way: potr[i] = *(potr[i].next); If you wanted to change the address of potr[i] with that stored in potr[i].next, you can't do it because since potr is an array, it is a constant pointer
27th Nov 2020, 1:46 PM
Davide
Davide - avatar
0
Create a program that consists of dynamic information about the bus in the bus fleet. Information about each bus includes: - bus number (number); - The driver's name; - direction number; The program should provide the following: - provide preliminary information about all buses in the fleet in the form of a list; - When each bus leaves the fleet, its number is entered and the information about it is removed from the list of buses in the fleet and added to the list of buses on the route; https://code.sololearn.com/cpQE1cFMoxb9/?ref=app
27th Nov 2020, 4:11 PM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
I tried to solve this problem.
27th Nov 2020, 4:12 PM
Fayzullo Abduhakimov
Fayzullo Abduhakimov - avatar
0
I don't know wait for the answer of someone more familiar with c++.
27th Nov 2020, 4:41 PM
Davide
Davide - avatar