digitalmars.D - queue container?
- J Arrizza <cppgent0 gmail.com> Oct 25 2011
--bcaec53aec3eee132204b02a8b1a
Content-Type: text/plain; charset=ISO-8859-1
I need a Queue (put on the front and pop from the back). The best I can
come up with so far is:
Array!string list;
list.insertBack("a1");
list.insertBefore(list.opSlice(0,1), "a2");
list.insertBefore(list.opSlice(0,1), "a3");
list.insertBefore(list.opSlice(0,1), "a4");
list.insertBefore(list.opSlice(0,1), "a5");
while (!list.empty())
{
string s = list.back();
list.removeBack();
writeln("x: ", s);
}
Having to insertBack when the list empty and insertBefore with the range,
seems strange to me. Is there a better way?
John
--bcaec53aec3eee132204b02a8b1a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div><div>I need a Queue (put on the front and pop from the back). =A0The b=
est I can come up with so far is:</div><div><br></div><div><div><font class=
=3D"Apple-style-span" face=3D"'courier new', monospace">=A0 =A0 Arr=
ay!string list;</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0 =A0 list.insertBack("a1");</font></div><div><font class=
=3D"Apple-style-span" face=3D"'courier new', monospace">=A0 =A0 lis=
t.insertBefore(list.opSlice(0,1), "a2");</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0 =A0 list.insertBefore(list.opSlice(0,1), "a3");</font></=
div><div><font class=3D"Apple-style-span" face=3D"'courier new', mo=
nospace">=A0 =A0 list.insertBefore(list.opSlice(0,1), "a4");</fon=
t></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0 =A0 list.insertBefore(list.opSlice(0,1), "a5");</font></=
div><div><font class=3D"Apple-style-span" face=3D"'courier new', mo=
nospace"><br>
</font></div><div><font class=3D"Apple-style-span" face=3D"'courier new=
', monospace">=A0 =A0 while (!list.empty())</font></div><div><font clas=
s=3D"Apple-style-span" face=3D"'courier new', monospace">=A0 =A0 {<=
/font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0 =A0 =A0 =A0 string s =3D list.back();</font></div><div><font class=
=3D"Apple-style-span" face=3D"'courier new', monospace">=A0 =A0 =A0=
=A0 list.removeBack();</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0 =A0 =A0 =A0 writeln("x: ", s);</font></div><div><font cl=
ass=3D"Apple-style-span" face=3D"'courier new', monospace">=A0 =A0 =
}</font></div></div>
<div><br></div><div>Having to insertBack when the list empty and insertBefo=
re with the range, seems strange to me. Is there a better way?</div><div><b=
r></div><div>John<br><div><br></div><div><div><br></div><div><br></div>
</div></div></div>
--bcaec53aec3eee132204b02a8b1a--
Oct 25 2011








J Arrizza <cppgent0 gmail.com>