Professional Documents
Culture Documents
Cau 1 Linkedlist
Cau 1 Linkedlist
Cau 1 Linkedlist
// Code C
#include <stdio.h>
#include <stdlib.h>
printf("null");
}
// Helper function to insert new Node in the beginning of the linked list
void push(struct Node** head, int data)
{
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = *head;
*head = newNode;
}
RemoveDuplicates(head);
return 0;
}
// Code Java
class Main
{
// Helper function to print given linked list
public static void printList(Node head)
{
Node ptr = head;
while (ptr != null)
{
System.out.print(ptr.data + " -> ");
ptr = ptr.next;
}
System.out.println("null");
}
return head;
}
head = removeDuplicates(head);
// Code Python
ptr = head
while ptr:
print(ptr.data, end=" -> ")
ptr = ptr.next
print("None")
# Remove duplicates from a sorted list
def removeDuplicates(head):
current = head
return head
if __name__ == '__main__':
# input keys
keys = [1, 2, 2, 2, 3, 4, 4, 5]
head = removeDuplicates(head)