From db9fd35dacfd05113187f7bb613a1355374a8d60 Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Fri, 15 Dec 2017 19:57:28 +0530 Subject: [PATCH 01/10] IMPLEMENT HASH TABLE how to implement hash table --- .../IMPLEMENTING HASH TABLE/Hashtable.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java diff --git a/Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java b/Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java new file mode 100644 index 000000000..14f821436 --- /dev/null +++ b/Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java @@ -0,0 +1,79 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + + +import java.util.Scanner; +class Student{ + int key; + String date; + String name; + Student next; +} +class Hashtable{ + Scanner s=new Scanner(System.in); + + Student node=new Student(); + static Hashtable n=new Hashtable(); + Student arr[]=new Student[10]; + void Hash(){ + + System.out.print("enter input elements"); + for(int x=0;x<5;x++) { + Student node=new Student(); + node.key = s.nextInt(); + node.date=s.next(); + node.name=s.next(); + + int v= n.calculate(node.key); + +if (arr[v]==null) +{ +node.next=null; +arr[v]=node; +} +else +{ + Student ptr; + ptr=arr[v]; + while(ptr.next!=null){ + ptr=ptr.next; + } + ptr.next=node; + node.next=null; +} + } + } + int calculate(int value) + { + int index =value%10; + return index; + } + void display() + { + for(int i=0;i<10;i++){ + if(arr[i]==null) +{ +System.out.println(arr[i]); +} +else +{ +Student ptr=arr[i]; +while(ptr!=null) +{ +System.out.print("->"+ptr.key); + +ptr=ptr.next; +} +System.out.println(); +} + }} + public static void main(String args[]) + { + + n.Hash(); + n.display(); + } +} From 05ba78932963134670638dab141cb1b184661cb7 Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Fri, 15 Dec 2017 20:12:11 +0530 Subject: [PATCH 02/10] Queue using linked list --- Competitive Coding/Linked List/queue (1).java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Competitive Coding/Linked List/queue (1).java diff --git a/Competitive Coding/Linked List/queue (1).java b/Competitive Coding/Linked List/queue (1).java new file mode 100644 index 000000000..65e5cd15c --- /dev/null +++ b/Competitive Coding/Linked List/queue (1).java @@ -0,0 +1,64 @@ +class node +{ +int data; +node link; +} +class queue +{ +node rear=null; +node top=null; +void push(int x) +{ + +node temp=new node(); +temp.data=x; +if(top==null) +{ +rear=temp; +//System.out.print(temp.data); +top=temp; +temp.link=null; +} +else +{ +node ptr=rear; +while(ptr.link!=null) +{ +ptr=ptr.link; +} +ptr.link=temp; +temp.link=null; +//System.out.print(temp.data); +} +} +void pop() +{ +rear=rear.link; +//System.out.print("n"); +} +void display() +{ +node ptr=rear; +while(ptr!=null) +{ +System.out.println(ptr.data+" "); +ptr=ptr.link; +} +} +public static void main(String args[]) +{ + +queue t=new queue(); +t.push(1); +t.push(2); +t.push(3); +t.push(4); +t.push(5); +t.push(6); + +t.pop(); + +t.display(); + +} +} From 675602cd73d119b886b2f9e6e2f1802ad82500cc Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Fri, 15 Dec 2017 20:15:23 +0530 Subject: [PATCH 03/10] Delete Hashtable.java --- .../IMPLEMENTING HASH TABLE/Hashtable.java | 79 ------------------- 1 file changed, 79 deletions(-) delete mode 100644 Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java diff --git a/Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java b/Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java deleted file mode 100644 index 14f821436..000000000 --- a/Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - - -import java.util.Scanner; -class Student{ - int key; - String date; - String name; - Student next; -} -class Hashtable{ - Scanner s=new Scanner(System.in); - - Student node=new Student(); - static Hashtable n=new Hashtable(); - Student arr[]=new Student[10]; - void Hash(){ - - System.out.print("enter input elements"); - for(int x=0;x<5;x++) { - Student node=new Student(); - node.key = s.nextInt(); - node.date=s.next(); - node.name=s.next(); - - int v= n.calculate(node.key); - -if (arr[v]==null) -{ -node.next=null; -arr[v]=node; -} -else -{ - Student ptr; - ptr=arr[v]; - while(ptr.next!=null){ - ptr=ptr.next; - } - ptr.next=node; - node.next=null; -} - } - } - int calculate(int value) - { - int index =value%10; - return index; - } - void display() - { - for(int i=0;i<10;i++){ - if(arr[i]==null) -{ -System.out.println(arr[i]); -} -else -{ -Student ptr=arr[i]; -while(ptr!=null) -{ -System.out.print("->"+ptr.key); - -ptr=ptr.next; -} -System.out.println(); -} - }} - public static void main(String args[]) - { - - n.Hash(); - n.display(); - } -} From 19700c42d956b59b1feba7be5f67bdf94c35d091 Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Fri, 15 Dec 2017 20:17:12 +0530 Subject: [PATCH 04/10] Update queue (1).java --- Competitive Coding/Linked List/queue (1).java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Competitive Coding/Linked List/queue (1).java b/Competitive Coding/Linked List/queue (1).java index 65e5cd15c..cf6869f79 100644 --- a/Competitive Coding/Linked List/queue (1).java +++ b/Competitive Coding/Linked List/queue (1).java @@ -1,16 +1,16 @@ -class node +class Node { int data; -node link; +Node link; } -class queue +class Queue { -node rear=null; -node top=null; +Node rear=null; +Node top=null; void push(int x) { -node temp=new node(); +Node temp=new Node(); temp.data=x; if(top==null) { @@ -21,7 +21,7 @@ void push(int x) } else { -node ptr=rear; +Node ptr=rear; while(ptr.link!=null) { ptr=ptr.link; @@ -38,7 +38,7 @@ void pop() } void display() { -node ptr=rear; +Node ptr=rear; while(ptr!=null) { System.out.println(ptr.data+" "); From dde7df83b4e0a3967ac10381dc2e1dba13e4f9e5 Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Fri, 15 Dec 2017 20:18:31 +0530 Subject: [PATCH 05/10] Update and rename queue (1).java to queue .java --- Competitive Coding/Linked List/{queue (1).java => queue .java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Competitive Coding/Linked List/{queue (1).java => queue .java} (88%) diff --git a/Competitive Coding/Linked List/queue (1).java b/Competitive Coding/Linked List/queue .java similarity index 88% rename from Competitive Coding/Linked List/queue (1).java rename to Competitive Coding/Linked List/queue .java index cf6869f79..000e66dbe 100644 --- a/Competitive Coding/Linked List/queue (1).java +++ b/Competitive Coding/Linked List/queue .java @@ -48,7 +48,7 @@ void display() public static void main(String args[]) { -queue t=new queue(); +Queue t=new Queue(); t.push(1); t.push(2); t.push(3); From 10f6013b9376c28e47be37f19d2f48051ed00261 Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Fri, 15 Dec 2017 20:42:51 +0530 Subject: [PATCH 06/10] Update queue .java --- Competitive Coding/Linked List/queue .java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Competitive Coding/Linked List/queue .java b/Competitive Coding/Linked List/queue .java index 000e66dbe..6a0e48eb6 100644 --- a/Competitive Coding/Linked List/queue .java +++ b/Competitive Coding/Linked List/queue .java @@ -1,13 +1,13 @@ -class Node +public class Node { -int data; -Node link; +public int data; +public Node link; } -class Queue +public class Queue { -Node rear=null; -Node top=null; -void push(int x) +public Node rear=null; +public Node top=null; +public void push(int x) { Node temp=new Node(); @@ -31,12 +31,12 @@ void push(int x) //System.out.print(temp.data); } } -void pop() +public void pop() { rear=rear.link; //System.out.print("n"); } -void display() +public void display() { Node ptr=rear; while(ptr!=null) From 9b42fc38918edac402d86c48a8faf1515db17304 Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Sat, 16 Dec 2017 15:30:46 +0530 Subject: [PATCH 07/10] Update queue .java --- Competitive Coding/Linked List/queue .java | 1 + 1 file changed, 1 insertion(+) diff --git a/Competitive Coding/Linked List/queue .java b/Competitive Coding/Linked List/queue .java index 6a0e48eb6..57080b576 100644 --- a/Competitive Coding/Linked List/queue .java +++ b/Competitive Coding/Linked List/queue .java @@ -1,3 +1,4 @@ +package LinkedList; public class Node { public int data; From 04fa17741b7968a90b32e1cada704a38a07cf4fb Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Sat, 16 Dec 2017 15:32:53 +0530 Subject: [PATCH 08/10] Update queue .java --- Competitive Coding/Linked List/queue .java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Competitive Coding/Linked List/queue .java b/Competitive Coding/Linked List/queue .java index 57080b576..539234f66 100644 --- a/Competitive Coding/Linked List/queue .java +++ b/Competitive Coding/Linked List/queue .java @@ -16,7 +16,6 @@ public void push(int x) if(top==null) { rear=temp; -//System.out.print(temp.data); top=temp; temp.link=null; } @@ -29,13 +28,11 @@ public void push(int x) } ptr.link=temp; temp.link=null; -//System.out.print(temp.data); } } public void pop() { rear=rear.link; -//System.out.print("n"); } public void display() { @@ -48,7 +45,6 @@ public void display() } public static void main(String args[]) { - Queue t=new Queue(); t.push(1); t.push(2); @@ -56,10 +52,7 @@ public static void main(String args[]) t.push(4); t.push(5); t.push(6); - t.pop(); - t.display(); - } } From b2f6a680d364ef37831425bd6b0aec2d87ba4bf7 Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Sat, 16 Dec 2017 15:36:32 +0530 Subject: [PATCH 09/10] Update queue .java --- Competitive Coding/Linked List/queue .java | 1 - 1 file changed, 1 deletion(-) diff --git a/Competitive Coding/Linked List/queue .java b/Competitive Coding/Linked List/queue .java index 539234f66..c5014d481 100644 --- a/Competitive Coding/Linked List/queue .java +++ b/Competitive Coding/Linked List/queue .java @@ -10,7 +10,6 @@ public class Queue public Node top=null; public void push(int x) { - Node temp=new Node(); temp.data=x; if(top==null) From 065cc1c068b89b59e372b4c04b4377f779572b92 Mon Sep 17 00:00:00 2001 From: KavyaSaxena <34169165+KavyaSaxena@users.noreply.github.com> Date: Sat, 16 Dec 2017 15:40:55 +0530 Subject: [PATCH 10/10] Update queue .java --- Competitive Coding/Linked List/queue .java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Competitive Coding/Linked List/queue .java b/Competitive Coding/Linked List/queue .java index c5014d481..282073f66 100644 --- a/Competitive Coding/Linked List/queue .java +++ b/Competitive Coding/Linked List/queue .java @@ -1,4 +1,4 @@ -package LinkedList; +package linkedlist; public class Node { public int data;