摘要:
http://www.geeksforgeeks.org/detect-and-remove-loop-in-a-linked-list/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 struct node {13 int data;14 node *next;15 node() : data(0), next(NULL) { }16 n... 阅读全文
摘要:
http://www.geeksforgeeks.org/reverse-a-list-in-groups-of-given-size/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 struct node {13 int data;14 node *next;15 node() : data(0), next(NULL) { }16 no... 阅读全文
摘要:
http://www.geeksforgeeks.org/merge-sort-for-linked-list/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 struct node {13 int data;14 node *next;15 node() : data(0), next(NULL) { }16 node(int d) : ... 阅读全文
摘要:
http://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/第一第二个方法比较简单,下面这段代码是第三个方法 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 struct node {13 int data;14 node *n... 阅读全文
摘要:
http://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/这里的reverse可以reverse整个list,这样空间需求就是O(n),不如这个网页写的O(1)的方法 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 struct node {13 int ... 阅读全文
摘要:
iterative太简单不写了http://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 struct node {13 int data;14 node *next;15 node() : d... 阅读全文
摘要:
http://www.geeksforgeeks.org/move-zeroes-end-array/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 void movezero(int arr[], int n) {13 int c = 0;14 for (int i = 0; i < n; i++) {15 if (arr[i] == 0... 阅读全文
摘要:
http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 bool zerosubarray(int arr[], int n) {13 set S;14 int sum = 0;15 for (int i = 0; i <... 阅读全文
摘要:
http://www.geeksforgeeks.org/increasing-subsequence-of-length-three-with-maximum-product/ 阅读全文
摘要:
http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-than-nk-times/这一题如果没空间要求就没那么麻烦了 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 void more(int arr[], int n, int k) {12 map ... 阅读全文