Created
April 8, 2013 02:44
-
-
Save whoo24/5333845 to your computer and use it in GitHub Desktop.
재귀를 이용해 링크드 리스트 출력하기
print linked list using recursive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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