bag implementation that uses inside a stack logic