#include #include "hexdump.h" using namespace std; struct Liste { int wert; Liste* next; }; ostream& operator<<(ostream& o,Liste* l) { o << "["; while (l!=0) { o << l->wert; l=l->next; if (l) o << ","; } o << "]"; return o; } // Rekursive Variante von addBack void addBack(Liste*& l,int wert) { if (l==0) { l=(Liste*)malloc(sizeof(Liste)); l->wert = wert; l->next=0; } else addBack(l->next,wert); } void addBackPtr(Liste** l,int wert) { if (*l==0) { *l=(Liste*)malloc(sizeof(Liste)); *l->wert = wert; *l->next=0; } else addBackPtr(&(l->next),wert); } // iterative Vairante von addBack2 void addBack2(Liste*& l,int wert) { Liste** lauf=&l; while (*lauf) lauf=&(*lauf)->next; (*lauf)=(Liste*)malloc(sizeof(Liste)); (*lauf)->next=0; (*lauf)->wert=wert; } void addFront(Liste*& l,int wert) { Liste* oldList = l; l=(Liste*)malloc(sizeof(Liste)); l->wert=wert; l->next=oldList; } int main(int argc,char** argv) { Liste* l= 0; addBack2(l,-4); addBack(l,256); addFront(l,12); cout << l << endl; cout << "Hexdump der Liste:" << endl; cout << hexdump(*l) << endl; cout << hexdump(*l->next) << endl; cout << hexdump(*l->next->next) << endl; }