System Verilog Queue Example
module queues;
byte qu [$] ;
initial
begin
qu.push_front(1);
qu.push_front(2);
qu.push_front(3);
qu.push_back(4);
qu.push_back(5);
foreach(qu[i])begin
$display(i,qu[i]);
end
qu.delete(3); //Delete element at index 3
$display(" %d ",qu.pop_front() ); // pop_front operation removes first element
$display(" %d ",qu.size() );
foreach(qu[i])begin
$display(i,qu[i]);
end
$display(" %d ",qu.pop_back() ); // pop_back operation removes last element
foreach(qu[i])begin
$display(i,qu[i]);
end
$display(" %d ",qu.size() );
end
endmodule
OUTPUT:
0 3
1 2
2 1
3 4
4 5
3
3 //pop front
0 2
1 1
2 5
5 //pop back
0 2
1 1
2