+------------+
| 'a' | NULL |
+------------+
#aabb
+-------------+ +-------------+ +------------+
| 'a' | #aa01 | --> | 'b' | #aabb | --> | 'c' | NULL |
+-------------+ +-------------+ +------------+
#0a01 #aa01 #aabb
Jazyk C, ani štandardná knižnica nepoznajú spojkový zoznam.
struct node {
int value;
struct node* next;
};
struct node one_node;
one_node.value = 1;
one_node.next = NULL;
struct node* linked_list = malloc(sizeof(struct node));
linked_list->value = 1;
linked_list->next = NULL;
free(linked_list);
(struct node*)malloc(sizeof(struct node));
->
.sizeof
.()
.struct node* linked_list = malloc(sizeof(struct node));
linked_list->value = 1;
linked_list->next = NULL;
struct node* next_node = malloc(sizeof(struct node));
next_node->value = 2;
next_node->next = NULL;
linked_list->next = next_node;
free(next_node);
free(linked_list)
struct node* add_node(struct node* first, int value){
struct node* newnode = calloc(1,sizeof(struct node));
newnode->value = value;
newnode->next = first;
return newnode;
}
struct node* add(struct node* list,int value) {
// Vytvorenie nového prvku
struct node* item = (struct node*)malloc(sizeof(struct node));
item->value = value;
item->next = NULL;
if (list == NULL){
list = item;
}
else {
// Vyhladanie posledneho prvku
struct node* this=list;
while(this->next != NULL){
this = this->next;
}
this->next = item;
}
return list;
}
void delete(struct node* list){
if (list!=NULL){
delete(list->next);
free(list);
}
}
struct node* this = first;
while(this != NULL){
this = this->next;
}
for(struct node* this = linked_list;this != NULL;this = this->next){
if (this->value == 'a'){
printf("Nasiel som a");
}
}
struct node* this = first;
while(this->next != NULL){
this = this->next;
}