Professional Documents
Culture Documents
:-
METHOD-1 :-
#include <stdlib.h>
#include <stdio.h>
void mainMenu();
int data;
int i = 1;
Head->data = i;
Head->next = Head;
last = Head->next;
t->data = i;
t->next = last->next;
last->next = t;
last = t;
do
h = h->next;
} while (h != Head);
printf("\n");
int len = 0;
do
len++;
p = p->next;
} while (p != Head);
return len;
int i, x;
if (index < 0)
return -1;
if (index == 1)
p = p->next;
x = Head->data;
p->next = Head->next;
free(Head);
Head = p->next;
else
p = p->next;
q = p->next;
x = q->data;
free(q);
return x;
int i = 1;
Display(Head);
getchar();
}
printf("The winner of this game is ");
Display(Head);
void gameRules()
printf("GAME RULES\n");
printf("2. Total number of levels will be one less than the total number of players.\n");
printf("3. In each level one player will be eliminated based on the value of k
(Josephus Problem).\n");
getchar();
mainMenu();
void credits()
printf("CREDITS\n");
mainMenu();
void gameSetup()
int n, k;
scanf("%d", &n);
scanf("%d", &k);
getchar();
create(n);
getchar();
Display(Head);
getchar();
play(Head, k);
void intro()
{
printf("__________________________________");
printf("__________________________________");
printf("__________________________________");
printf("__________________________________");
getchar();
void mainMenu()
int num = 0;
printf("Main Menu\n");
scanf("%d", &num);
if (num == 1)
gameSetup();
else if (num == 2)
gameRules();
else if (num == 3)
credits();
else if (num == 4)
return;
else
printf("Invalid response!");
printf("\n");
getchar();
mainMenu();
int main()
intro();
mainMenu();
return 0;
}
METHOD-2 :-
#include <stdio.h>
#include <stdlib.h>
void delete (int *number, int startpos) // deleting by shifting it to the last
int i;
if (length == 1)
return;
else
length--;
play(number, startpos);
int i;
number[i] = i + 1;
length++;
printf("\n");
getchar();
}
int main()
int n;
getchar();
scanf("%d", &n);
scanf("%d", &k);
getchar();
create(n);
int startpos = 0;
play(number, startpos);
return 0;
}
1. What is the running time of your method if you
implement with the chosen first data structure
and terms of n and k?
O(n^2)
2. What is the running time of your method if you
implement with the chosen second data structure
and terms of n and k?
O(n^2)