circular linked list question..
i need to go from the head of the linked list
and check if i got to the same place
after making circle.
the problem is if tell ptr=head;
and then the while condition checks if i didnt got to this place.
so it doesnt even enters this loop.
how to solve it
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node node;
struct node{
int value;
struct node * next;
};
void main()
{
node* head;
head=(node*)malloc(sizeof(node));
head->next=(node*)malloc(sizeof(node));
head->next->next=(node*)malloc(sizeof(node));
head->next->next->next=(node*)malloc(sizeof(node));
head->next->next->next->next=(node*)malloc(sizeof(node));
head->next->next->next->next->next=(node*)malloc(sizeof(node));
head->next->next->next->next->next->next=head;
head->value=2;
head->next->value=4;
head->next->next->value=1;
head->next->next->next->value=5;
head->next->next->next->next->value=3;
head->next->next->next->next->next->value=8;
}
int checkround(node *head)
{
int temp=head->value,n_temp;
node * ptr;
node * h_ptr
ptr=head;//i need this in order to start going threw the list from this place
while(ptr!=head)///have problem here
{
for(temp=n_temp;tem>0;temp=temp-1)
{
ptr=ptr->next;
}
n_temp=ptr->value;
ptr->value=-1;
}
}