Iteratable single linked list of floats.
Alain De Vos
devosalain at ymail.com
Wed Apr 21 13:11:51 UTC 2021
I try to create manually and explicit an interetable single
linked list of floats. Probably one of the most basic
datastructures.
import std.stdio;
void main(){
struct List {
struct Node {
float f;
Node *next;
}
Node * root=null;
bool empty() const {return !root;}
void popFront() {root=root.next;}
float front() const {return root.f;}
void push(float f) {
Node * newnode=new Node();
newnode.f=f;
root.next=newnode; // Segmentation fault
}
}
List * l=new List();
l.push(3);
foreach(element;l){ // Invalid foreach aggregate
writeln(element.root.f);
}
}
But I have a segmentation fault and an invalid foreach aggregate
More information about the Digitalmars-d-learn
mailing list