Skip to content

Instantly share code, notes, and snippets.

@kirkconnell
Last active December 16, 2015 02:18
Show Gist options
  • Save kirkconnell/5360899 to your computer and use it in GitHub Desktop.
Save kirkconnell/5360899 to your computer and use it in GitHub Desktop.
std::list<int> list;
std::list<int>::iterator pos;
pos = list.begin();
list.insert(it, 1024);
pos = std::find(list.begin(), list.end(), 1024);
*pos; // get
list.erase(pos);
list.front();
list.back();
pos = list.begin();
pos++ // next
pos-- // previous
list.clear();
list.size();
list = []
list.insert(1, :first)
list.index(:first)
list.at(1)
list.delete_at(1)
list.first
list.last
# previous and next make no sense, since the positions are numeric
list.clear
list.size
DECLARE
pos SCROLL CURSOR (pt_id integer) FOR SELECT id FROM pages WHERE page_template_id = pt_id;
page_id integer;
BEGIN
OPEN pos(pt_id := 42);
FETCH pos INTO page_id; -- next
FETCH LAST FROM pos INTO page_id; -- last
FETCH FIRST FROM pos INTO page_id; -- first
FETCH ABSOLUTE 10 FROM pos INTO page_id; -- get
FETCH PRIOR FROM pos INTO page_id; -- previous
-- Direction options: NEXT, PRIOR, FIRST, LAST, ABSOLUTE count, RELATIVE count, FORWARD, or BACKWARD
CLOSE pos;
END;
std::queue<int> queue;
for (int i=0; i<5; ++i) queue.push(i);
cout << "Popping out elements...";
while (!queue.empty())
{
cout << " " << mystack.front(); // peek
mystack.pop();
}
queue = []
(0...5).each { |e| queue.push(e) }
puts "Popping out elements..."
until queue.empty?
puts " #{queue.last}" # peek
queue.shift # pop
end
std::stack<int> stack;
for (int i=0; i<5; ++i) stack.push(i);
cout << "Popping out elements...";
while (!stack.empty())
{
cout << " " << mystack.top(); // peek
mystack.pop();
}
stack = []
(0...5).each { |e| stack.push(e) }
puts "Popping out elements..."
until stack.empty?
puts " #{stack.last}" # peek
stack.pop
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment