Created
April 22, 2015 04:10
-
-
Save songpu2015617/eea86116db12bddcba70 to your computer and use it in GitHub Desktop.
cc150 2.6
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> | |
# inclue <map> | |
using namespace std; | |
typedef struct node{ | |
int data; | |
node *next; | |
}node; | |
node* cyclelinklist(node *head){ | |
if (head=NULL) return NULL; | |
node *fast=head, *slow=head; | |
while (fast&&fast->next){ | |
fast=fast->next->next; | |
slow=slow->next; | |
if (slow == fast) break; | |
} | |
if (!fast||!fast->next) return NULL; | |
fast=head; | |
while (slow !=fast){ | |
fast=fast->next; | |
slow=slow->next; | |
} | |
return slow; | |
} | |
map<node*,bool> hash; | |
node* cyclelinklist1 (node *head){ | |
if (head==NULL) return NULL; | |
while (head){ | |
if (hash[head]) return head; | |
else{ | |
hash[head]=true; | |
head=head->next; | |
} | |
} | |
return head; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment