cout has inbuilt support for multiple types, easier than using printf. Just have to ease the compiler into it
51 lines
812 B
C++
51 lines
812 B
C++
/* list.cpp
|
|
* Date: 2021-11-20
|
|
* Author: Aryadev Chavali
|
|
*/
|
|
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
|
|
template <typename T>
|
|
struct List
|
|
{
|
|
T value;
|
|
struct List<T> *next;
|
|
};
|
|
|
|
template <typename T>
|
|
List<T> *append(List<T> *lst, T value)
|
|
{
|
|
List<T> *node;
|
|
if (lst == NULL)
|
|
{
|
|
node = new List<T>;
|
|
node->value = value;
|
|
node->next = NULL;
|
|
return node;
|
|
}
|
|
|
|
for (node = lst; node->next != NULL; node = node->next)
|
|
continue;
|
|
|
|
node->next = new List<T>;
|
|
node->next->value = value;
|
|
node->next->next = NULL;
|
|
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;
|
|
}
|