Skip to content

Commit

Permalink
요세푸스 문제
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghaemi committed Nov 20, 2023
1 parent 8a317fb commit 5a0ae38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions 1158.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void deletenode(int k)
{
node *temp = head;
head = head->next;
cout << temp->data;
delete temp;
return;
}
Expand All @@ -56,6 +57,7 @@ void deletenode(int k)
}
node *temp = cur->next;
cur->next = cur->next->next;

head = cur->next;
cout << temp->data;
delete temp;
Expand All @@ -65,41 +67,30 @@ void deletenode(int k)
return;
}

void getList()
{
node *cur = head;

for (int i = 0; i <= Copy_n; i++)
{
cout << cur->data << "->";
cur = cur->next;
}
cout << '\n';
}

int main()
{

int i;
cin >> n >> k;
Copy_n = n;
if (n == 1)
{
cout << "<1>";
return 0;
}
headnode(1); // 1은 헤드로 삽입
if (i >= 2)
if (n >= 2)
{
for (i = 2; i <= n; i++)
for (int i = 2; i <= n; i++)
{
insert(i); // 2~n까지 연결리스트 연결
}
}

// getList();
cout << "<";

for (int j = 0; j < n - 1; j++)
{
deletenode(k);
cout << ", ";
// getList();
}
deletenode(k);
cout << ">";
Expand Down
Binary file removed 1158.exe
Binary file not shown.

0 comments on commit 5a0ae38

Please sign in to comment.