Skip to content

Commit 4a53470

Browse files
committed
* 'master' of https://github.com/AlgorithmCrackers/Data-Structures: fixes #1 also the useless constructor is removed Seperation of java and c implementation Conflicts: Linked-Lists/Java/LinkedList.java
2 parents b794f47 + b593b54 commit 4a53470

12 files changed

+66
-0
lines changed

Diff for: Binary-Trees/traversals.c

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void preorder_nonrecursive ( struct node *tree ) {
7373
}
7474
}
7575
// move left, visit, move right
76+
// see http://imgur.com/9RxHnr8
7677
void inorder_nonrecursive ( struct node* tree ) {
7778
/*
7879
Inorder traversal is harder. We need to walk to the left without losing any
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: Linked-Lists/Java/LinkedList.java

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Linked List Implementation
3+
4+
*/
5+
class Node {
6+
int data;
7+
Node next;
8+
Node prev;
9+
}
10+
class LinkedList {
11+
Node head;
12+
Node tail;
13+
14+
boolean insertFront(int newData) {
15+
Node newNode = new Node();
16+
newNode.data = newData;
17+
18+
if(head == null ) {
19+
head = newNode;
20+
tail = head;
21+
return true;
22+
}
23+
else {
24+
Node oldHead = head;
25+
head = newNode;
26+
head.next = oldHead;
27+
oldHead.prev = head;
28+
return true;
29+
}
30+
}
31+
32+
boolean insertTail(int newData) {
33+
Node newNode = new Node();
34+
newNode.data = newData;
35+
if(head == null ) {
36+
head = newNode;
37+
tail = head;
38+
return true;
39+
}
40+
else {
41+
//Node oldTail = tail;
42+
newNode.prev = tail;
43+
tail.next = newNode;
44+
tail = newNode;
45+
return true;
46+
}
47+
}
48+
int delete(int data) {
49+
return 0;
50+
}
51+
void printList(){
52+
Node cur = head;
53+
while(cur != null) {
54+
System.out.println(cur.data);
55+
cur = cur.next;
56+
}
57+
}
58+
public static void main(String[] args) {
59+
LinkedList ll = new LinkedList();
60+
ll.insertFront(30);
61+
ll.insertFront(20);
62+
ll.insertFront(10);
63+
ll.printList();
64+
}
65+
}
File renamed without changes.

0 commit comments

Comments
 (0)