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
/* | |
* test.cpp | |
*Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures? | |
* Created on: 2013-5-4 | |
* Author: Fred | |
*/ | |
#include <iostream> | |
#include <string> |
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
/* | |
* test.cpp | |
Given two strings, write a method to decide if one is a permutation of the other. | |
* Created on: 2013-5-5 | |
* Author: Fred | |
*/ | |
#include <iostream> | |
#include <string> | |
using namespace std; |
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 <string> | |
#include <sstream> | |
using namespace std; | |
string conv2str(int num){ | |
ostringstream ostr; //output string stream | |
ostr << num; //use the string stream just like cout, | |
return ostr.str(); | |
} |
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 <algorithm> | |
#include <string> | |
using namespace std; | |
bool ifanagram(string str1,string str2){ | |
if(str1.length()!=str2.length()) return false; | |
sort(str1.begin(),str1.end()); |
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; |
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
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
#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
// 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
// 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; |
OlderNewer