aboutsummaryrefslogtreecommitdiff
path: root/list.cpp
blob: 009ed9a2f2db3cb8e4ebca6cbe315a2250f252d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* 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;
}