
Untitled
By: a guest on
May 10th, 2012 | syntax:
C++ | size: 0.83 KB | hits: 19 | expires: Never
#include <stdio.h>
#include <stdlib.h>
// wsk->zm to (*wsk).zm czyli wyłuskanie adresu obiektu struktury
typedef struct list_element
{
struct list_element *next;
int value;
} element;
int insert_end(element *&lista, int wartosc)
{
element *nowy;
element *help;
help=lista;
nowy = (element*)malloc(sizeof(element));
nowy->value = wartosc;
nowy->next = NULL;
if(lista==NULL)
{
lista = nowy;
return 0;
}
while(help->next != NULL)
{
help = help->next;
}
help->next = nowy;
return 0;
}
int read(element *lista)
{
element *help = lista;
while(help->next!=NULL)
{
printf("%d\n",help->value);
help = help->next;
}
printf("%d\n",help->value);
return 0;
}
int main()
{
element *list = NULL;
insert_end(list,10);
insert_end(list,15);
insert_end(list,20);
read(list);
}