padh.ayo@gmail.com writes:
Quote:
Hi, I just have a few questions maybe you guys can verify for
correctness:
.
>
21) Show how you would insert a new element "new_element" into a
linked list "my_list"
>
my_list new_element = my_list->next;
That doesn't insert anything into anything. It's just an
initialization. Presumably my_list is a pointer type.
Quote:
Just for MY verification: If you want to create a link list in C, do
you need a structure all the time? I know how to create it that way,
but just curious if there are any other ways.
Normally a linked list will include some kind of auxiliary data
in each node, in addition to the linked list pointers themselves.
The way C provides to bind together different types of data items
in a single package is to use a structure.
Other ways may be possible, but they'd probably be much more
awkward. For example, I suppose you could use an array of two or
more pointers to form a linked list node, but it wouldn't
normally be sensible to do so. (I could see a Lisp
implementation in C might want to do that, but even then it might
be better to use a structure.)
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}