'How do I sort int without stl liberaries [closed]

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

c++


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Armin Montigny