Re: Problem with linked lists
- From: Sven Neumann <sven gimp org>
- To: Szymon Bąkowski <szymonbakowski klub chip pl>
- Cc: <gtk-list gnome org>
- Subject: Re: Problem with linked lists
- Date: 21 Aug 2002 15:20:06 +0200
Hi,
Szymon Bąkowski <szymonbakowski klub chip pl> writes:
> Second question:
> I wanted to use in the same program function g_list_position but I`m not
> sure If I assigned wright the second argument
> of this function - it shoud be some element of my list, and I should be able
> to chceck his position but I`m not sure if temp_elem
> could be this element and hou it should be assigned.
>
> for example: (assuming that I my list is big enougth)
> komp_list = g_list_next(komp_list);
> komp_list = g_list_next(komp_list);
> komp_list = g_list_next(komp_list);
> temp_elem=komp_list;
> pozycja_lista = g_list_position(komp_list,temp_elem);
> g_print("the position of element is %d\n",pozycja_lista);
>
> //for example should be 4 assuming that we start counting from 0
the result will be 0 since komp_list is the list starting with
temp_elem (both variables point at the same list element). The mistake
you make here is that you don't save the start of the list. You should
always keep a pointer to the start of the list and use a second list
pointer to iterate over it.
Salut, Sven
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]