Code Snippet

You might also like

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 1

bool has_cycle(SinglyLinkedListNode* head) {

SinglyLinkedListNode* slow;
SinglyLinkedListNode* fast;
slow=head;
fast=head;
while(fast&&slow&&fast->next)
{
slow=slow->next;
fast=fast->next->next;
if(slow==fast)
{
return true;
}
}
return false;
}

gcd:

int gcd(int a,int b)

if(a==0) return b;

else{

return(b%a,a);

inversion:

for(i=0;i<n-1;i++)

{
for(j=i+1;j<n;j++)
{
if(q[i]>q[j])
cnt++;
}
}

You might also like