#include "list.h"
#include <iostream>
#include <cstdlib>
using namespace std;
/*
Node* prefix(int value, Node* head)
{
head = new Node(value,head);
return head;
}
*/
int main()
{
// singlton list model
// create the first node with a pointer variable referencing it
// singleton list model
/*
Node* head = new Node;
head->setValue(0);
head->setNext(NULL);
*/
Node headNode(0,NULL);
Node* head = &headNode;
// null list model
/*
Node* head = NULL;
head = prefix(0,head);
*/
for(int i = 1; i < 1000; ++i)
head = head->prefix(i,head);
// make copy of head to traverse our list
Node* trav = head;
while(trav != NULL)
{
cout << trav->value << endl;
trav = trav->next;
}
free(head); // return memory allocated to the list structure to the freestore
return 0;
}
I2luY2x1ZGUgImxpc3QuaCIKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8qCk5vZGUqIHByZWZpeChpbnQgdmFsdWUsIE5vZGUqIGhlYWQpCnsKICBoZWFkID0gbmV3IE5vZGUodmFsdWUsaGVhZCk7CiAgcmV0dXJuIGhlYWQ7Cn0KKi8KCmludCBtYWluKCkKewogIC8vIHNpbmdsdG9uIGxpc3QgbW9kZWwKICAvLyBjcmVhdGUgdGhlIGZpcnN0IG5vZGUgd2l0aCBhIHBvaW50ZXIgdmFyaWFibGUgcmVmZXJlbmNpbmcgaXQKICAKICAvLyBzaW5nbGV0b24gbGlzdCBtb2RlbAogIC8qCiAgTm9kZSogaGVhZCA9IG5ldyBOb2RlOwogIGhlYWQtPnNldFZhbHVlKDApOwogIGhlYWQtPnNldE5leHQoTlVMTCk7CiAgKi8KICAKICBOb2RlIGhlYWROb2RlKDAsTlVMTCk7CiAgTm9kZSogaGVhZCA9ICZoZWFkTm9kZTsKICAKICAvLyBudWxsIGxpc3QgbW9kZWwKICAvKgogIE5vZGUqIGhlYWQgPSBOVUxMOwogIGhlYWQgPSBwcmVmaXgoMCxoZWFkKTsKICAqLwoKICBmb3IoaW50IGkgPSAxOyBpIDwgMTAwMDsgKytpKQogICA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