namespace SLL {
class Node {
constructor(
public data,
public next: Node = null,
) {}
}
// export class so it can be used outside namespace
export class List {
private head;
push(data) {
const node = new Node(data);
node.next = this.head;
this.head = node;
}
}
}
const list = new SLL.List();
for (let i=3; i>0; i--) { list.push(i); }
console.log(list);
To embed this project on your website, copy the following code and paste it into your website's HTML: