Informatics3-2024/Linked
A MathWikiből
A lap korábbi változatát látod, amilyen Kkovacs (vitalap | szerkesztései) 2024. március 14., 11:00-kor történt szerkesztése után volt.
#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; }