Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Queue: SystemVerilog Queue Methods Example

SystemVerilog Arrays

Runnable example from the SystemVerilog Queue tutorial (SystemVerilog Queue Methods Example)

Open in IDE
testbench.sv
module tb;
	string fruits[$] = '{"apple", "pear", "mango", "banana"};
  
	initial begin
		// size() - Gets size of the given queue
		$display ("Number of fruits=%0d   fruits=%p", fruits.size(), fruits);
  
		// insert() - Insert an element to the given index
		fruits.insert (1, "peach");
		$display ("Insert peach, size=%0d fruits=%p", fruits.size(), fruits);
  
		// delete() - Delete element at given index
		fruits.delete (3);
		$display ("Delete mango, size=%0d fruits=%p", fruits.size(), fruits);
  
		// pop_front() - Pop out element at the front
		$display ("Pop %s,    size=%0d fruits=%p", fruits.pop_front(), fruits.size(), fruits);
  
		// push_front() - Push a new element to front of the queue
		fruits.push_front("apricot");
		$display ("Push apricot, size=%0d fruits=%p", fruits.size(), fruits);
  
		// pop_back() - Pop out element from the back
		$display ("Pop %s,   size=%0d fruits=%p", fruits.pop_back(), fruits.size(), fruits);
  
		// push_back() - Push element to the back
		fruits.push_back("plum");
		$display ("Push plum,    size=%0d fruits=%p", fruits.size(), fruits);
	end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.