Informatics3-2024/Linked
A MathWikiből
(Változatok közti eltérés)
(Új oldal, tartalma: „#include<iostream> using namespace std; struct list_e { int num; struct list_e *next; }; void append(struct list_e **start, int n) { struct list_e *e = new str…”) |
|||
1. sor: | 1. sor: | ||
+ | <c> | ||
#include<iostream> | #include<iostream> | ||
32. sor: | 33. sor: | ||
return 0; | return 0; | ||
} | } | ||
+ | </c> |
A lap jelenlegi, 2024. március 14., 11:00-kori változata
#include<iostream> using namespace std; struct list_e { int num; struct list_e *next; }; void append(struct list_e **start, int n) { struct list_e *e = new struct list_e; e->num = n; e->next = NULL; if (*start == NULL) { *start = e; } else { struct list_e *p = NULL; for(p = *start; p->next != NULL; p = p->next){} p->next = e; } } int main(void) { struct list_e *start = NULL; append(&start, 1); append(&start, 5); append(&start, -2); append(&start, 15); for(struct list_e *e = start; e != NULL; e = e->next) { cout << e->num << endl; } return 0; }