Skip to content

Instantly share code, notes, and snippets.

View Vidmich's full-sized avatar

Dmytro Vidmych Vidmich

View GitHub Profile
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;
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;
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;
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;
int count(Node* head) {
int n = 0;
while (NULL != head) {
++n;
head = head->next;
}
return n;
}
struct Node {
int data;
Node* next;
};
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);
});
async(function*() {
try {
yield async(function*() {
var a = yield delay(1, 1000);
throw new Error('some error');
});
} catch(e) {
console.log(e);
}
});
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) {
try {
async(function*() {
var a = yield delay(1, 1000);
throw new Error('some error');
});
} catch(e) {
console.log(e);
}