This file contains hidden or 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
| Node* getLoop(Node* head) { | |
| if (NULL == head) | |
| return NULL; | |
| // reverse list | |
| int n = 0; | |
| Node* rest = head->next; | |
| head->next = NULL; | |
| while (NULL != rest) { | |
| ++n; |
This file contains hidden or 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 hasCycle(Node* head) { | |
| if (NULL == head) | |
| return false; | |
| // reverse list | |
| Node* rest = head->next; | |
| head->next = NULL; | |
| while (NULL != rest) { | |
| Node* t = rest; | |
| rest = t->next; |
This file contains hidden or 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 hasCycle(Node* head) { | |
| if (NULL == head) | |
| return false; | |
| // reverse list | |
| Node* rest = head->next; | |
| head->next = NULL; | |
| while (NULL != rest) { | |
| Node* t = rest; | |
| rest = t->next; |
This file contains hidden or 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 hasCycle(Node* head) { | |
| if (NULL == head) | |
| return false; | |
| // reverse list | |
| Node* rest = head->next; | |
| head->next = NULL; | |
| while (NULL != rest) { | |
| Node* t = rest; | |
| rest = t->next; |
This file contains hidden or 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
| int count(Node* head) { | |
| int n = 0; | |
| while (NULL != head) { | |
| ++n; | |
| head = head->next; | |
| } | |
| return n; | |
| } |
This file contains hidden or 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
| struct Node { | |
| int data; | |
| Node* next; | |
| }; |
This file contains hidden or 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
| async(function*() { | |
| var a = yield delay(1, 1000); | |
| throw new Error('some error'); | |
| }).then(function(v) { | |
| // some result from function | |
| // in most cases will be undefined | |
| }, function(e) { | |
| console.log(e); | |
| }); |
This file contains hidden or 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
| async(function*() { | |
| try { | |
| yield async(function*() { | |
| var a = yield delay(1, 1000); | |
| throw new Error('some error'); | |
| }); | |
| } catch(e) { | |
| console.log(e); | |
| } | |
| }); |
This file contains hidden or 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
| function async(f) { | |
| var d = jQuery.Deferred(); | |
| var g = f(); // get generator | |
| function h(v, e) { | |
| var t; | |
| try { | |
| t = e ? g.throw(e) : g.send(v); | |
| } catch(e) { |
This file contains hidden or 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
| try { | |
| async(function*() { | |
| var a = yield delay(1, 1000); | |
| throw new Error('some error'); | |
| }); | |
| } catch(e) { | |
| console.log(e); | |
| } |
NewerOlder