This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class partitionLinkedList { | |
public static LinkedListNode Solution(LinkedListNode head, int x) { | |
if (head == null) return null; | |
LinkedListNode smaller = new LinkedListNode(0); //dummyhead for list called smaller | |
LinkedListNode smallerPtr = smaller; | |
LinkedListNode larger = new LinkedListNode(0); //dummyhead for list called larger | |
LinkedListNode largerPtr = larger; | |
LinkedListNode result; | |
while (head != null) { | |
if (head.val < x) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class findKth { | |
public static LinkedListNode solution(LinkedListNode head, int Kth) { | |
if (Kth < 0) return null; | |
if (head == null) return null; | |
LinkedListNode walker = head; | |
LinkedListNode runner = head; | |
for (int i = 0; i < Kth-1; i++) { | |
if (runner == null) return null; | |
runner = runner.next; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Hashtable; | |
public class removeDuplicates { | |
public static void Solution(LinkedListNode head) { | |
if (head == null) return; | |
Hashtable<Integer, Boolean> table = new Hashtable<Integer, Boolean>(); | |
LinkedListNode dummyHead = new LinkedListNode(0); | |
dummyHead.next = head; | |
LinkedListNode ptr = dummyHead; | |
while(ptr.next != null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <map> | |
using namespace std; | |
template <class T> | |
struct node{ | |
T data; | |
node *next; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Linkedlist.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
#include <iostream> | |
using namespace std; | |
template <class T> | |
struct node{ | |
T data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Linkedlist.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
#include <iostream> | |
using namespace std; | |
struct node{ | |
int data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stack> | |
using namespace std; | |
class MyException{ | |
public: | |
MyException(){cout << "the stack is empty" << endl;} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool isPalindrome(node *head){ | |
if(head==NULL) return false; | |
node *curr = head; | |
stack<int> s; | |
while(curr!=NULL){ | |
s.push(curr->data); | |
curr = curr->next; | |
} | |
/*while(!s.empty()){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void delGivenNode(node *entry){ | |
entry->data = (entry->next)->data; | |
entry->next = (entry->next)->next; | |
delete entry->next; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Remove duplicates from an unsorted linked list - cc2.1*/ | |
void removeDuplicate1(node *head){ | |
map<int,bool> table; | |
node *curr = head; | |
node *pre = NULL; | |
while(curr!=NULL){ | |
/*delete the node if it already exists in the map*/ | |
if(table[curr->data]){ | |
pre->next = curr->next; | |
delete curr; |
NewerOlder