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.
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 10 months ago.
Improve this question
I have a problem where I need to sort buses arriving at a bus station on the basis of time of arrival without using STL (standard template library) in ascending order
You may first want to read about sorting algorithms in general. A good staring point is here.
There you see many of them.
The recommendation for newbies is to start with bubble sort.
Please see here for an example including source code.
Then, you need to store your bus data in a struct. Along with the timing information. All those struct shoulb be stored in an array, best a std::vector.
Then you need to write a compare function for times. The complexity of this depends, if you have one varaible that stores the complete time, like in a unix timestamp, or in a struct, for example tm. Then you need to compare hours, minutes and seconds and some boolean relation.
But first, you need to read a lot, then think even longer on how to implement, and then write the code.
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 6 years ago.
Improve this question
During the run of my c++ program I have an amount of data that I will use.
I want to be able to use some of it depending on some criterion. In other words, a kind of data base with request instructions.
Is it possible to create an internal database and use it with DB request instructions?
I don't need to save the data either before or after the run.
Edit:
It won't be feasable in my case to add other C libraries, I'll have to work with what i'm provided with.
You may like to have a look at SQLite in-memory database.
Alternatively, use a container with one or more indexes, e.g. boost::multi_index.
You can use some database theory:
1. Store all the records into std::vector.
2. Use std::map to build search / index tables.
The index tables will give you quicker search times on keys without having to sort all the data. The index table will be of the form std::map<Key_Type, unsigned int>, where the unsigned int is the index into the std::vector database.
You can use a in memory structure, depending on how big this database needs to be. Is it a collection of Structs or is it a proper relational database or just tons of unstructured data?
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm new to OOP and I'm trying to create a program. Basically it's a store and it has products and clients and all that stuff. However, I'm struggling with a question.
When it comes to OOP, does it make sense to create a class to represent the stock of the products? Something like:
class Stock
{
private:
Product *_product;
int _nrOfProducts;
...
};
I'm asking because initially I had thought about it being an atribute of the product but then I started wondering things like "What if I delete a product? All of its information will be lost - including the stock, which I still need".
Thanks in advance!
A lot of tutorials will tell you otherwise, but in general objects are better at modeling abstractions in your software that capture behavior rather than modelling objects in the physical world. That's just data, whereas an object or better yet an interface is about capturing and abstracting behavior that can vary depending upon the situation.
As to the decision to cache the number of products v.s. not. The typical answer is, "It depends." Frequently you won't need to, because you'll be using a more sophisticated collection type that gives you an easy "count" operation. You might need that stored separately for some other reason though.
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 have a problem which requires data to be stored in memory for users. The structure contains user_name and phone_number and I have to store it for say 1 million users. Now while retrieving if user_name is given as input then it should return the phone_number and if phone_number is given as input then it should return the user_name. What will be the appropriate data structure to implement this when I need optimized complexity while retrieving in terms of speed and storage.
try boost::bimap.
It's a bidirectional map (everything is a key and also a value).
Boost.Bimap
I think it's implemented with two maps though so note the memory usage.
Try leveldb, where you can store data in the form of key & value pairs.
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 9 years ago.
Improve this question
I have read that Binary Indexed Trees are very efficient. But I couldn't anything more than that. If anybody knows about that, please share your knowledge.
This solution will help you. There are direct algorithms available and this explanation is a good one I could see
This is how the author of the blog has described Binary indexed Tree
We often need some sort of data structure to make our algorithms faster. In this article we will discuss the Binary Indexed Trees structure. According to Peter M. Fenwick, this structure was first used for data compression. Now it is often used for storing frequencies and manipulating cumulative frequency tables.