Edit queue using associative index;

queue q[$] = {5,1,2,3,4,5}
index ind[*] = {0,0,1,0,1,0}
How can I edit q to have zeros on the index where associative ind has 1?

In reply to Aashish Itani:

Firstly, the declaration of queue & associative array is not proper. I hope your question is in associative array in whichever index you have 1, in that particular index of queue you should have zeros.



module test;
  
int q[$] = {5,1,2,3,4,5};
  int ind[int]={0:0,1:0,2:1,4:0,7:1,10:0};
int idx;
int idx1;

initial
  begin
    if(ind.first(idx))
      if(ind[idx]==1)
        q.insert(idx,0);
    
    if(ind.last(idx1))
      if(ind[idx1]==1)
        q.insert(idx1,0);
    
    while(idx!=idx1)
      if(ind.next(idx))
      if(ind[idx]==1)
        q.insert(idx,0);
    
    $display("%p,%p",q,ind);
  end
endmodule





Thanks & Regards,
Shanthi V A

In reply to shanthi:

Thanks a lot.

In reply to Aashish Itani:


// modify q to have zeros on the index where associative array has 1
module test;
  int q[$] = {5,1,2,3,4,5,7,11,2};
  int ind[int] = {0:1,3:0,5:1,6:0,8:1};
  int q1[$];
  initial begin
    q1 = ind.find_index with(item == 1);
    $display("q1 = %0p", q1);
    foreach(q1[i]) begin
      q.insert(q1[i], 0);
    end
    $display("q = %0p", q);
    foreach(q1[i]) begin
      q.delete(q1[i]+1);
    end
    $display("q = %0p", q);
  end  
endmodule : test