• 全部
• 问答

# 请教一道简单的题目

jp1984 2004-03-15 11:00:06

void r_reverseOutput(list<T>::iterator first,list<T>::iterator last)
...全文
73 点赞 收藏 12

12 条回复

gameboy007 2004-03-21

#include <iostream>
#include <list>

using namespace std;

template<typename T>
void r_reverseOutput(typename list<T>::iterator first, typename list<T>::iterator last)
{
while (true) {
swap(*first, *--last);
if (first == last)
break;
else if (++first == last)
break;
}
}

int main()
{
int v[] = { 1,2,3,4,5 };
list<int> a(v,v+sizeof(v)/sizeof(v[0]));

r_reverseOutput<int>(a.begin(), a.end());

list<int>::iterator beg(a.begin());
while (beg != a.end())
cout << *beg++ << " ";

system("PAUSE");
}

jp1984 2004-03-21

jp1984 2004-03-20

gameboy007 2004-03-20

jp1984 2004-03-20

gameboy007 2004-03-20

template<typename T>
void r_reverseOutput(list<T>::reverse_iterator first,list<T>::reverse_iterator last)
{
while (first != last) {
first->DoSomthing(); 对各个元素實行其调用
if (*first == condition) 達到停止条件後离开while loop
break;
++first;
}
first->DoOther();
}

list<T>::iterator itr(find(ctr.rbegin(), ctr.rend(), T_value));

jp1984 2004-03-17

gameboy007 2004-03-16
template<typename T>
void r_reverseOutput(list<T>::reverse_iterator first,list<T>::reverse_iterator last)
{
}

reverseOutput(container.rbegin(), container.rend());

jp1984 2004-03-16

jp1984 2004-03-16

dahan2005 2004-03-16

congliu 2004-03-15

C++ 语言

5.9w+

C++ 语言相关问题讨论，技术干货分享，前沿动态等

2004-03-15 11:00