1class Node {
2 Object data;
3 Node next;
4 Node(Object d,Node n) {
5 data = d ;
6 next = n ;
7 }
8
9 public static Node addLast(Node header, Object x) {
10 // save the reference to the header so we can return it.
11 Node ret = header;
12
13 // check base case, header is null.
14 if (header == null) {
15 return new Node(x, null);
16 }
17
18 // loop until we find the end of the list
19 while ((header.next != null)) {
20 header = header.next;
21 }
22
23 // set the new node to the Object x, next will be null.
24 header.next = new Node(x, null);
25 return ret;
26 }
27}
1typedef struct node{
2 int value; //this is the value the node stores
3 struct node *next; //this is the node the current node points to. this is how the nodes link
4}node;
5
6node *append(node *head, int val){
7 node *tmp = head;
8 node *createdNode = createNode(val);
9
10 while(tmp->next != NULL){
11 tmp = tmp->next;
12 }
13
14 tmp->next = createdNode;
15 return head;
16}
1class Node:
2 def __init__(self, dataval=None):
3 self.dataval = dataval
4 self.nextval = None
5class SLinkedList:
6 def __init__(self):
7 self.headval = None
8# Function to add newnode
9 def AtEnd(self, newdata):
10 NewNode = Node(newdata)
11 if self.headval is None:
12 self.headval = NewNode
13 return
14 laste = self.headval
15 while(laste.nextval):
16 laste = laste.nextval
17 laste.nextval=NewNode
18# Print the linked list
19 def listprint(self):
20 printval = self.headval
21 while printval is not None:
22 print (printval.dataval)
23 printval = printval.nextval
24
25list = SLinkedList()
26list.headval = Node("Mon")
27e2 = Node("Tue")
28e3 = Node("Wed")
29
30list.headval.nextval = e2
31e2.nextval = e3
32
33list.AtEnd("Thu")
34
35list.listprint()