大数据工程师笔试题
}
Iterator<Integer> it=new MergeIterator(new MockIterator(2,10),new MockIterator(2,9));
//输出2 3 4 5 6 7 8 9 10
C++:
Struct Iterator{
Virtual bool hasNext()=0;
Int m_current,m_step,m_endValue;
Public:
MockIterator(int step,int endValue){
m_step=step;
m_endValue=endValue;
m_current=endValue%step;
}
Bool hasNext(){return m_current < m_endValue;}
Int next(){ return m_current += m_step;}
};
MockIterator ita(2,10),itb(2,9);
MergeIterator it(&ita,&itb);//输出2 3 4 5 6 7 8 9 10
Virtual int next()=0;
};
Class MergeIterator : public Iterator{
Public:
MergeIterator(){}
Bool hasNext(){}
Int next(){}
}
测试用例:
Class MockIterator : public Iterator{
Public Integer next(){}
}
测试用例:
Class MockIterator implements Iterator<Integer>{
Int current,step,endValue;
Public MockIterator(int step,int endValue){
this.step=step;
链表排序
Java:
class Node{
Int value;
Node next;
}
C++:
strode* pNext;
}
请实现如下函数对任意给定链表按照其中的value字段排序
Java:
Node sortList(Node head);
C++:
Node* sortList(Node* pHead);
This.endValue=endValue;
This.current=endValue%step;
}
Public boolean hasNext(){return this.current < this.endValue;}
Public Integer next(){return this.current += this.step;}
解答:
编写归并排序迭代器
java:
class MergeIterator implements Iterator<Integer>{
Public MergeIterator(Iterator<Integer> a,Iterator<integer> b){}
Public boolean hasNext(){}