Skip to content

Instantly share code, notes, and snippets.

@whoo24
Created April 8, 2013 02:44
Show Gist options
  • Save whoo24/5333845 to your computer and use it in GitHub Desktop.
Save whoo24/5333845 to your computer and use it in GitHub Desktop.
재귀를 이용해 링크드 리스트 출력하기 print linked list using recursive
#include <list>
#include <algorithm>
using namespace std;
void printlist(list<int>::iterator iter, list<int>::iterator& end)
{
if( iter == end)
return;
int n = *iter;
printlist(++iter, end);
printf("%d\n", n);
}
int main()
{
list<int> l;
l.push_back(1);
l.push_back(2);
l.push_back(3);
l.push_back(4);
l.push_back(5);
l.push_back(6);
list<int>::iterator it = l.begin();
printlist(it, l.end() );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment