Informatics3-2024/Linked

A MathWikiből
(Változatok közti eltérés)
Kkovacs (vitalap | szerkesztései)
(Ú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…”)
Újabb szerkesztés →

A lap 2024. március 14., 10:59-kori változata

  1. 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;

}

Személyes eszközök