aboutsummaryrefslogtreecommitdiff
path: root/list.cpp
blob: 937e7a7123cbc149ca5a8353af76c5aac683d99c (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
/* list.cpp
 * Date: 2021-11-20
 * Author: Aryadev Chavali
 */

#include <cstdio>
#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;
}

int main(void)
{
  return 0;
}