@ pavan : thanks...
@utkarsh : please find attached code......please le me knw if any case fail
On Thu, Feb 16, 2012 at 7:02 PM, pavan <[email protected]> wrote:
> yeah the results are correct for the given inputs
>
> On Feb 16, 1:03 am, atul anand <[email protected]> wrote:
> > if i have understood the problem correctly...
> > you please confirm the answers i am getting for the given inputs:-
> > result
> > 1) 1 2 3 4 5 4
> > 2) 1 2 3 4 5 6 5
> > 3) 1 2 3 4 5 6 7 4
> > 4) 1 2 3 4 5 6 7 8 8
> >
> > On Wed, Feb 15, 2012 at 11:38 PM, Dheeraj Sharma <
> >
> > [email protected]> wrote:
> > > yeah..we need to calculate some formula
> >
> > > On Wed, Feb 15, 2012 at 10:21 PM, pavan <[email protected]> wrote:
> >
> > >> @Utkarsh: yeah it is josephsus problem with a slight change.....using
> > >> a linked list will give u TLE i guess.
> >
> > >> On Feb 14, 10:36 pm, vickywiz <[email protected]> wrote:
> > >> > in 1 2 3 4 5 6...o/p "ll b 5
> >
> > >> --
> > >> You received this message because you are subscribed to the Google
> Groups
> > >> "Algorithm Geeks" group.
> > >> To post to this group, send email to [email protected].
> > >> To unsubscribe from this group, send email to
> > >> [email protected].
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/algogeeks?hl=en.
> >
> > > --
> > > *Dheeraj Sharma*
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
# include <stdio.h>
# include <stdlib.h>
struct node
{
int data;
struct node *link;
};
struct node *insert(struct node *p, int n)
{
struct node *temp;
if(p==NULL)
{
p=(struct node *)malloc(sizeof(struct node));
if(p==NULL)
{
printf("Error\n");
exit(0);
}
p-> data = n;
p-> link = p;
}
else
{
temp = p;
while (temp-> link != p)
temp = temp-> link;
temp-> link = (struct node *)malloc(sizeof(struct node));
if(temp -> link == NULL)
{
printf("Error\n");
}
temp = temp-> link;
temp-> data = n;
temp-> link = p;
}
return (p);
}
void printlist ( struct node *p )
{
struct node *temp;
temp = p;
if(p!= NULL)
{
do
{
printf("%d\t",temp->data);
temp=temp->link;
} while (temp!= p);
}
else
printf("The list is empty\n");
}
struct node *del(struct node *start,int val)
{
struct node *p=NULL;
struct node *tmp=NULL;
int flag=0;
if(start->link==start)
{
return start;
}
p=start;
while(p->link!=start)
{
if(p->link->data==val)
{
tmp=p->link;
p->link=p->link->link;
tmp=NULL;
free(tmp);
flag=1;
break;
}
p=p->link;
}
if(p->link->data==val && flag==0)
{
tmp=p->link;
p->link=start->link;
tmp=NULL;
free(tmp);
start=p->link;
}
return start;
}
void main()
{
int n;
int x;
int total,shoot,cnt=1,flag=0,j=1;
struct node *start = NULL ,*tmp=NULL;
printf("Enter the nodes to be created = ");
scanf("%d",&n);
printf("\n\n");
total=n;
while ( n-- > 0 )
{
start = insert ( start, j );
j++;
}
shoot=1;
printf("\n\nList Formed\n\n");
printlist(start);
printf("\n\n");
while(total>1)
{
cnt=1;
while(cnt<shoot)
{
start=start->link;
cnt++;
}
start=del(start,start->data);
total--;
shoot++;
}
printf("\nAlive Girl = %d\n",start->data);
}