Advertisement

Beat This

Started by July 14, 2005 12:36 AM
20 comments, last by GameDev.net 19 years, 6 months ago
#include <iostream>template<class T>class Node {public:    Node() {next = NULL;}    Node(T newData) {next = NULL; data = newData;}    ~Node() {delete next;}    void Add(T newData) {        if (next)            next->Add(newData);        else            next = new Node<T>(newData); }    void Print() {        std::cout << data << std::endl;        if (next)            next->Print(); }    Node* next;    T data;};//And an example of it's useint main(){    Node<int> list(1);    list.Add(2);    list.Add(3);    list.Print();    system("PAUSE");    return 0;}


Not the most intuitive list ever, but it's templated which must count for something. Besides, it only took 5 minutes. It does use stl, but only for output. 19 lines, and almost readable.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
This has nothing to do with Ai it is just something i started since i was bored and i did not bother checking where i was posting so i am sorry that i have posted it in the AI section.

By the way sjelkjd don't used my code and pretend like it is yours.
Advertisement
Quote:
Original post by BornToCode
This has nothing to do with Ai it is just something i started since i was bored and i did not bother checking where i was posting so i am sorry that i have posted it in the AI section.

By the way sjelkjd don't used my code and pretend like it is yours.


He's just trying to be amusing, and I am amused at least. Btw, wouldn't something a little more challenging be interesting?
Line count can be abused - such as in my example. You can also chain together long seqeuences of operations with the comma operator.

And as moogleii observed, I don't think anyone was going to mistake my second example as anything but your code, compacted onto 2 lines.
Do I win for taking it seriously?
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
no you did not win. you did not implement the delete part, but beside that very nice
Advertisement
It has nothing to do with AI. You should've posted it in the General forum
1 line of pseudocode:

Add some items to the list, delete them all, then print the contents of the list

This topic is closed to new replies.

Advertisement