Enthuziast
Enthuziast

Reputation: 1205

Arrays in stacks in c++

I want to stack or queue arrays/vectors in c++.

I've tried multiple variants, including with vectors, but unsuccessful. I thought this would be a quite "standard" problem, but cannot fint resources on it. Here is one suggested implementation of queuing vectors, but compilation doesn't like it.

#include <queue> 
queue<int[2]> q; 
q.push({9,3});
q.push({5,2});

Upvotes: 1

Views: 746

Answers (1)

tdao
tdao

Reputation: 17668

This q.push({9,3}); does not work because C-style array does not have initialise-list constructor.

One solution is to use std::array instead of C-style array as the type of your queue:

#include <array>

std::queue<std::array<int, 2>> q; 
q.push({9,3});
q.push({5,2});

Upvotes: 5

Related Questions