Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm currently working on a Simulation with autonomous agents and I'm trying to implement a wayfinding algorithm. In my program there are Rooms which are connected to each other. Each agent should have his own limited map of the system and expand it by wandering through the rooms and adding them to the map. If they get a task to go to a specific room which is in their map they should get a vector with the best route from their current location to the destination. I'm still on beginners level and the only data structures I used so far are vectors and structs. Could someone point me into the right direction?
I suggest that you create a Room class that contains a vector that holds a subscript to the rooms that it is connected to.
You system class could then hold a vector of Rooms that are subscriptable.
Your agents could have their own vector of Rooms that they populate while they travel, or a vector of subscript of the rooms that they have visited.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I've been working on a project that is supposed to recreate the tripulation of a plane.
I couldn't figure out how to program a key feature that I want it to have.
How can I generate a set number of objects that pick their parameters from a predefined list? For example, suppose we have the class "Passenger" which takes the parameters Name, Age, Nationality and phoneNumber. I need the program to generate, let's say 10 objects of the class passenger and take their attributes randomly from an array of 20 preset names. I know I could define 10 objects by myself, but what happens if I want to generate like 100 of them? Is there a way to do it?
Thanks in advance!
You could create a vector that contains the specified number of objects and then use a for loop to dynamically create and insert Passenger objects into that vector. For random properties, just get a random number the same size as your predefined lists and get the element at that index.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
private:
vector<float*> m_values;
vector<float> *m_index;
vector<float*> *m_rowptr;
What would be the best way to save a large data structure, using vectors?
The way to store a large quantity of floats is:
vector<float> m_index;
The vector manages the block of floats for you.
Making a pointer to the vector is pointless (hah!).
Making a vector of pointers is (usually*) not correct for your task, and it introduces a host of performance problems.
Making both things a pointer combines the two problems.
* Depending what you mean by "index", this may be one of those times. If you want a vector of "pointers to float", then make that thing.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
So we know that the basic structures which form the backbone of C++ algorithms are:
trees set
queue
linkedlist
array
vector map
unordered_map and pair.
My question is which data structure is suitable for which application.For instance I know that for Database indexing and searching preferred choices are B+ tree and Hash table.Can anyone shed some more light on this,
This is not only a C++ problem, but also an algorithm question. It maybe too broad, but I can give you some advice.
set and map: They are ordered container, it is used for a both manytimes-insert-and-read structure. It can finish insert delete read in O(logn) time.
vector: used for something like dynamic array or a structure you will frequently push_back at it, and if no other reason, you should use it.
deque: much like vector, but it can also finish push_front in O(1) time
list: used for a structure you need to frequently insert, but less random access
unordered_map and unordered_set: look for hash table
array: used for a structure whose size is fixed.
pair and tuple: bind many object into one struct. Nothing special
Beside all of this, there are also some container meeting other requirement, you can serach them.
e.g. any and optional
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i need some help in deciding which data structure i should use. i'm going to create a patient information system of a hospital just like a simple student information system.
i have studied Arrays, Linked Lists, Trees, Stacks, Queues and Graphs. i think it would be too simple with Array. should i use linked list?
how will i store all the fields into it? a Linked list stores one item of data at the moment, no? my requirements are to add information, search them by their ID and be able to delete through ID as well.
any ideas? thanks
my requirements are to add information, search them by their ID and be able to delete through ID as well.
Seems like an std::map<id, patient> would suit your needs via:
operator[] to add a record
at/find for retrieval
erase for removal
If you need more complex queries I'd recommend a full-fledged relational database.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm making a Monopoly game for a school project, written in C++. The first thing I'm working on is implementing the board. It's intuitive to me that each tile will be an object holding information and functions and whatnot, but I cannot decide whether these should be contained in a linked list or array.
It made sense for a linked list because i could simply have the last tile point to the first, but it also seems more efficient to use an array since I can instantly access Tile[5] for example.
Can anybody clarify as to which would be better for this purpose?
It's a fixed size. That negates about 90% of the advantages of a linked list.
You will NEVER be accessing it sequentially (unless, instead of dice, everybody just moves one square each time), but always randomly. That's about 90% of the advantage of an array.
The one reason you cite for using a linked-list is trivially handled differently. (new_position = (current_position + roll) % 40;)
Therefore: You unquestionably want to use an array.