Skip to content

Instantly share code, notes, and snippets.

View Mahdhir's full-sized avatar

Mahdhi Rezvi Mahdhir

View GitHub Profile
interface IDuck{
walk():void;
quack():void;
}
class Duck implements IDuck{
walk():void {
console.log("Duck walk");
}
class Pelican {
walk() {
console.log("Pelican walk");
}
quack() {
console.log("Pelican quack");
}
dive() {
let book = {
name: "Harry Potter 1",
price: {
value: 50,
currency: "EUR"
},
ISBN: "978-7-7058-9615-2",
weight: {
version1: {
value: 550,
let book = {
name: "Harry Potter 1",
price: {
value: 50,
currency: "EUR"
},
ISBN: "978-7-7058-9615-2",
weight: {
version1: {
value: 550,
Node search(int key){
Node temp = head;
while(temp != null){
if(temp.key == key){
return temp;
}
temp = temp.next;
}
return null;
}
void deleteNode(int position) {
if (head == null)
return;
Node temp = head;
if (position == 0) {
head = temp.next;
return;
}
public void insertAfter(Node prev_node, int new_data) {
if (prev_node == null) {
System.out.println("The given previous node cannot be null");
return;
}
Node new_node = new Node(new_data);
new_node.next = prev_node.next;
prev_node.next = new_node;
}
public void insertAtEnd(int new_data) {
Node new_node = new Node(new_data);
if (head == null) {
head = new Node(new_data);
return;
}
new_node.next = null;
public void insertAtBeginning(int new_data) {
// insert the data
Node new_node = new Node(new_data);
new_node.next = head;
head = new_node;
}
class LinkedList{
Node head; // head of list
public LinkedList(){
head=null;
}
public boolean isEmpty(){
return head==null;
}
}