We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,595 Members — Technology Publication meets Social Media

# how to sort int line by line

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

3
Contributors
6
Replies
1 Hour
Discussion Span
1 Year Ago
Last Updated
7
Views
salem13
Newbie Poster
3 posts since Mar 2012
Reputation Points: 10
Skill Endorsements: 0

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

``````start of loop
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.

Ancient Dragon
Achieved Level 70
Team Colleague
32,109 posts since Aug 2005
Reputation Points: 5,836
Skill Endorsements: 68

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.

MandrewP
Junior Poster
143 posts since Nov 2009
Reputation Points: 60
Skill Endorsements: 1

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

salem13
Newbie Poster
3 posts since Mar 2012
Reputation Points: 10
Skill Endorsements: 0

No.

MandrewP
Junior Poster
143 posts since Nov 2009
Reputation Points: 60
Skill Endorsements: 1

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.

Ancient Dragon
Achieved Level 70
Team Colleague
32,109 posts since Aug 2005
Reputation Points: 5,836
Skill Endorsements: 68

Thank you <<<<<<<<<Ancient Dragon>>>>>>>>>

salem13
Newbie Poster
3 posts since Mar 2012
Reputation Points: 10