Big issue with all permutations...

Hello I've a big problem. I'd like to generate of all permutations of objects present on my list and i don't know how to do this. I've found a few examples, but i can't use them in my code...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
#include <list>
#include <fstream>
#include <cstddef>
#include <cstdlib>
#include <iterator>
using namespace std;
class Item
  {
   private:
   int time, dist, index, deadline;
   public:
   Item(int time=0, int dist=0, int index=0, int deadline=0):time(time),dist(dist), index(index), deadline(deadline) {}
   int Time()const { return time; } //a
   int Dist()const { return dist; } //b
   int Index()const { return index; } //c
   int Deadline()const { return deadline; } //d

  };

int main()
{
    list<Item> Lst2;
    int a=0,b=0,c=0,d=0,n=0;
    ifstream filee;
    filee.open("tasks.txt", ios::in);
    filee>>n;
    for(int i=0; i<n; i++)
    {
        filee >> a >> b >> c >> d;
        Lst2.push_back(Item(a,b,c,d));
    }
    filee.close();
   for(list<Item>::iterator i=Lst2.begin();i!=Lst2.end();++i)
   {
   cout<<i->Time()<< " " <<i->Dist()<< " " <<i->Index()<< " " <<i->Deadline()<<endl;

   }


return 0;
}


Input file with objects:
3
2 0 0 4
5 0 1 5
3 0 2 6

and output should be:
2 0 0 4
5 0 1 5
3 0 2 6

2 0 0 4
3 0 2 6
5 0 1 5

3 0 2 6
2 0 0 4
5 0 1 5
etc...
3! so 6 permutations for this example.
I was 'fighting' with this for few days, and I'm so downcast. Give me some clues please...

I used std::cin to take values:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>

int main()
{
    using object = std::tuple<int, int, int, int>;
    std::vector<object> list;
    unsigned n;
    std::cin>>n;
    for(unsigned i=0; i<n; i++) {
        int a,b,c,d;
        std::cin >> a >> b >> c >> d;
        list.emplace_back(std::make_tuple(a, b, c, d));
    }
    std::sort(list.begin(), list.end());
    std::cout << std::endl;
    do {
        for(const auto& el: list) {
            std::cout << std::get<0>(el) << ' ' << std::get<1>(el) << ' ' <<
                         std::get<2>(el) << ' ' << std::get<3>(el) << '\n';
        }
        std::cout << std::endl;
    } while( std::next_permutation(list.begin(), list.end()) );
}
3
2 0 0 4
5 0 1 5
3 0 2 6

2 0 0 4
3 0 2 6
5 0 1 5

2 0 0 4
5 0 1 5
3 0 2 6

3 0 2 6
2 0 0 4
5 0 1 5

3 0 2 6
5 0 1 5
2 0 0 4

5 0 1 5
2 0 0 4
3 0 2 6

5 0 1 5
3 0 2 6
2 0 0 4
Last edited on
Woah! thank You so much!
Topic archived. No new replies allowed.