Re: Airplane Program with Linked Lists. The linked list ****tion is very confusing to me.
by "Chris Thomasson" <cristom@[EMAIL PROTECTED]
>
Mar 9, 2008 at 08:38 PM
"Chris Thomasson" <cristom@[EMAIL PROTECTED]
> wrote in message
news:DsadnZfGosSMfEzanZ2dnUVZ_gCdnZ2d@[EMAIL PROTECTED]
>
> "jawdoc" <drbrooks@[EMAIL PROTECTED]
> wrote in message
>
news:e66bcfe8-d62d-442f-b333-2ac4eb1b737a@[EMAIL PROTECTED]
> [...]
>
>> I just need some direction for using the linked lists instead
>> of the 2 dimensional arrays. Both versions are provided. Any help is
>> greatly appretiated.
>
> This should help get you started:
> ___________________________________________________________
> class airplane {
[...]
>
> struct row {
> row* next;
> seat* seats;
> };
[...]
> seat* find_seat(int row, int col) const {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
WHOOPS! Humm, I think I should rename the row variable in
'airplane::find_seat()'!
___________________________________________________________
class airplane {
struct seat {
seat* next;
// [...]
};
struct row {
row* next;
seat* seats;
};
row* m_rows;
seat* find_seat(
std::size_t idx_row,
std::size_t idx_col
) const {
row* r = m_rows;
while (r && idx_row > 1) {
idx_row--;
r = r->next;
}
if (r && idx_row == 1) {
seat* s = r->seats;
while (s && idx_col > 1) {
idx_col--;
s = s->next;
}
if (s && idx_col == 1) {
return s;
}
}
return NULL;
}
public:
// [...]
};
___________________________________________________________
Sorry about that non-sense. ;^)