HI

there is a string of 0 and 1, e.g. 00010111010

I want to sort it. 2 pairs can be switched on each step.

help me please

there is a string of 0 and 1, e.g. 00010111010

I want to sort it. 2 pairs can be switched on each step.

help me please

You need to implement it or you just want to sort it?

You just want to sort:

http://www.cplusplus.com/reference/algorithm/sort/

You want to implement it:

1) using specific knowledge about content:

count number of 0's and 1' adt then overwrite your string with required number of 0's and then 1's

2) Generic sort:

Use either selection or insertion sorts: they are easy and good for beginners

http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/insertion-sort/

http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/selection-sort/

Example of imlementation:

selection sort: http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort#C.2B.2B

insertion sort: http://en.cppreference.com/w/cpp/algorithm/rotate (look at the example part)

You just want to sort:

http://www.cplusplus.com/reference/algorithm/sort/

You want to implement it:

1) using specific knowledge about content:

count number of 0's and 1' adt then overwrite your string with required number of 0's and then 1's

2) Generic sort:

Use either selection or insertion sorts: they are easy and good for beginners

http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/insertion-sort/

http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/selection-sort/

Example of imlementation:

selection sort: http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort#C.2B.2B

insertion sort: http://en.cppreference.com/w/cpp/algorithm/rotate (look at the example part)

Let’s say there is a string of 0 and 1, e.g.g. 00010111010.

The goal is to sort it. 2 pairs can be switched on each step. For example the mentioned above string can be sorted in following steps:

0. 000__10__111__01__0

1. 0000__11__111__00__

2. 00000011111

I can solve this, but when it is

101010

in this case I can not swap 2bites in each step

The goal is to sort it. 2 pairs can be switched on each step. For example the mentioned above string can be sorted in following steps:

0. 000

1. 0000

2. 00000011111

I can solve this, but when it is

101010

in this case I can not swap 2bites in each step

Topic archived. No new replies allowed.