aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2021-11-20 22:50:05 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2021-11-20 22:50:05 +0000
commitfc6fc4032b54a5a8a8aababa3d5f16f8b5595507 (patch)
tree2e59cc2c79c0b04123a935792292d173ed792dae
parentfccfcd4a9f51f9d97a693a9b301157a9aa88db6f (diff)
downloadalgorithms-fc6fc4032b54a5a8a8aababa3d5f16f8b5595507.tar.gz
algorithms-fc6fc4032b54a5a8a8aababa3d5f16f8b5595507.tar.bz2
algorithms-fc6fc4032b54a5a8a8aababa3d5f16f8b5595507.zip
(list)+simple output mechanism via C++ streams
cout has inbuilt support for multiple types, easier than using printf. Just have to ease the compiler into it
-rw-r--r--list.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/list.cpp b/list.cpp
index 937e7a7..009ed9a 100644
--- a/list.cpp
+++ b/list.cpp
@@ -4,6 +4,7 @@
*/
#include <cstdio>
+#include <iostream>
#include <cstdlib>
template <typename T>
@@ -34,6 +35,15 @@ List<T> *append(List<T> *lst, T value)
return lst;
}
+template <typename T>
+std::ostream& operator<<(std::ostream& ostream, const List<T> *lst)
+{
+ if (lst == NULL)
+ return ostream;
+ ostream << "|" << lst->value << lst->next;
+ return ostream;
+}
+
int main(void)
{
return 0;