hi please I need help
how to sort int line by line & get number of int in each line
I have Input
4 2 32 8 6
10 7 9 21 2 3
14 1 5

Output must be
2 4 6 8 32 count = 5
2 3 7 9 10 21 count = 6
1 5 14 count = 3

6 Years
Discussion Span
Last Post by salem13

If you use vector<int> then you can use std::sort() to sort the numbers.

start of loop
    read a line
    split line into individual integers and put into vector
    call std::sort
    display values
end of loop

you can do the same with simple int array instead of vector, but then you would have to write you own sort algorithm.

Edited by Ancient Dragon: n/a

Votes + Comments
can you give me a code to do this

There are two things going on here - sorting the input in ascending order, and then counting the number of integers in a line.

So first off, you need a sorting algorithm to sort each line in ascending order. There are various sorting algorithms that you could use which you might want to Google. The easiest sort is the bubble sort, but this is the least efficient of the algorithms.

It may be easier to count the number of integers on each line first, then do the sorting.


Can any one write a code please>>>
I am beginner

Edited by salem13: n/a


We were all beginners at one time. The only way for you to learn is by coding it yourself, making mistakes, and learning how to correct your mistakes. There is a lot of self-satisfaction in knowing that you can accomplish something.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.