Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading to arrays of linked lists

Status
Not open for further replies.

lerequin5

Programmer
Dec 27, 1999
1
US
I designed the following<br>
pseudo code for a project I'm <br>
working on, I don't know much<br>
c++ so was wondering if n-e-1<br>
could translate:<br>
<br>
Open file &quot;filename&quot;<br>
Do until EOF:<br>
{<br>
i = i++<br>
Read Char<br>
If Char = &quot;#&quot;<br>
then <br>
{<br>
U<i>-&gt;flag = TRUE<br>
Char = NextChar<br>
}<br>
else U<i>-&gt;flag = FALSE<br>
Do until Char = &quot;,&quot;<br>
{<br>
Read Char<br>
NumberString = NumberString + Char<br>
}<br>
U<i>-&gt;value = StrToInt(NumberString)<br>
<br>
Do until EOL<br>
{<br>
j = j++<br>
Read Char<br>
If Char = &quot;#&quot;<br>
then <br>
{<br>
W<i>[j]-&gt;flag = TRUE<br>
Char = NextChar<br>
}<br>
else W<i>[j]-&gt;flag = FALSE<br>
Do until Char = &quot;,&quot;<br>
{<br>
Read Char<br>
NumberString = NumberString + Char<br>
}<br>
W<i>[j]-&gt;value = StrToInt(NumberString)<br>
}<br>
Goto NextLine<br>
}<br>
<br>
Example of what the code should do:<br>
Say I had text file such as:<br>
<br>
#0,#-0.1,0.2<br>
2,0.3,#0<br>
<br>
The code should read this and subsequently<br>
fill the data structures as follows:<br>
U[1]-&gt;flag = TRUE<br>
U[1]-&gt;value = 0<br>
W[1][1]-&gt;flag = TRUE<br>
W[1][1]-&gt;value = -0.1<br>
w[1][2]-&gt;flag = FALSE<br>
W[1][2]-&gt;value = 0.2<br>
U[2]-&gt;flag = FALSE<br>
U[2]-&gt;value = 2<br>
W[2][1]-&gt;flag = FALSE<br>
W[2][1]-&gt;value = 0.3<br>
w[2][2]-&gt;flag = TRUE<br>
W[2][2]-&gt;value = 0<br>
<br>
As you can see U and W are arrays.<br>
The elements of each array are<br>
also linked lists of flag(boolean)<br>
and value(double). U is a 1-D array<br>
while W is a 2-D array.
 
If I understood you question. Then U array holds the value for integers While W array holds floating point values. Is it ? And # corrsponds to TRUE value. <br>I think you shouldn't use array. If you are planning to use linked list. Because again if you are using array you need to specify some limit for it at compile time . But you do not know how long your value could be. So use only singly linked list with two fields. For eg.<br>&nbsp;U linked list will hold Flag and Value for integer values<br>& W linked list will hold Flag and Value for floating point&nbsp;&nbsp;values<br><br>If you need code in C/C++ , I can provide to you. Your pseudocode seems to have some faults.&nbsp;&nbsp;<br><br>Will it suffice ?<br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top