Develop a febonacci series of 20 numbers . Now push these elements into stack and then pop them . After pop , each element should get inserted into queue and after dequeuing each element should get inserted in linked list and then print that linked list .
using namespace std;
#define N 10
void DisplayQ(queue<long int> Queue)
{
while (!Queue.empty())
{
cout << Queue.front() << " ";
Queue.pop();
}
}
int main()
{
long int Fib[N],a=0,b=1,c;
int n;
queue<long int> Queue;
Fib[0] = a;
Queue.push(Fib[0]);
Fib[1] = b;
Queue.push(Fib[0]);
for(n=2;n<N;n++)
{
Fib[n] = a+b;
Queue.push(Fib[n]);
a=b;
b = Fib[n];
}
DisplayQ(Queue);
}
Comments
Leave a comment