Can anyone help me with this program?
Look at the bottom of this program for help methods: - /*1. Make a program that uses numbers from 1 to 100 including each ends which puts the even integers in the front of a double linked queue and the odd numbers in the back. Then prints out the deque.
-
-
2. Make a new deque list 2 that contain integers from 51 to 100. Print that list out as mine looks. Sort that list in decending order then print it out and keep the list less than 61 characters per line when you print it out.
-
3. Declare a new deque list 3 then use the resize() method to make it big enough to hold both list 1 and list 2 Next put list 1 in front of list 3 so it is
-
in accending order and put list 2 in the back of list 3 in the decending order.
-
4. Print list 3 out making sure you print only 60 characters or less on a line.
-
5. Sort list 3 in acending order and print it out and keep it 60 or less characters.
-
-
*/
-
#include <iostream>
-
// Notice I comment out the #include list.
-
//#include <list>
-
//#include algorithm has the merge and sort methods
-
#include <algorithm>
-
//deque means double link list
-
#include <deque>
-
-
using namespace std;
-
-
template<class T>
-
void printDeque(const deque<T>& lst, char *s) {
-
cout <<"The list is "<< s << ":"<< endl << endl;
-
int j = 0, k=0;
-
typename deque<T>::const_iterator i = lst.begin();
-
for ( ; i != lst.end(); i++)
-
{
-
//put your code here
-
}
-
-
-
int main() {
-
deque<int> dq1;
-
int i;
-
cout << " \n\n******This is your happy programming day working with Quiz 2!!!!!!!! "<< endl;
-
cout << " \n\nMake a program that uses numbers "<< endl;
-
cout << "from 1 to 100 including each 1 and 100 which puts the odd integers "<< endl;
-
cout << "in the front of a double linked queue and the even numbers in the back."<< endl;
-
cout << "Then prints out the deque. " <<endl;
-
cout << "You can also use the .cpp file attached to start your program." ;
-
cout << endl <<endl;
-
-
-
-
-
system("pause");
-
-
return 0;
-
} // End main()
-
-
-
/*
-
dq1.push_front(2); // dq1 = (2 1)
-
dq1.push_back(3); // dq1 = (2 1 3)
-
dq1.push_back(4); // dq1 = (2 1 3 4)
-
printDeque(dq1,"dq1");
-
deque<int> dq2(dq1.begin()+1,dq1.end()-1); //Jumps to second term and drops
-
printDeque(dq2,"dq2"); // dq2 = (1 3) // back one from the end
-
dq1[1] = 5;
-
printDeque(dq1,"dq1"); // dq1 = (2 5 3 4)
-
dq1.erase(dq1.begin());
-
printDeque(dq1,"dq1"); // dq1 = (5 3 4)
-
dq1.insert(dq1.end()-1,2,6);
-
printDeque(dq1,"dq1"); // dq1 = (5 3 6 6 4)
-
sort(dq1.begin(),dq1.end());
-
printDeque(dq1,"dq1"); // dq1 = (3 4 5 6 6)
-
deque<int> dq3;
-
dq3.resize(dq1.size()+dq2.size());
-
printDeque(dq3,"dq3"); // dq3 = (0 0 0 0 0 0 0)
-
merge(dq1.begin(),dq1.end(),dq2.begin(),dq2.end(),dq3.begin());
-
// dq1 = (3 4 5 6 6) and dq2 = (1 3) ==> dq3 = (1 3 3 4 5 6 6)
-
printDeque(dq1,"dq1"); // dq1 = (3 4 5 6 6)
-
printDeque(dq2,"dq2"); // dq2 = (1 3)
-
printDeque(dq3,"dq3"); // dq3 = (1 3 3 4 5 6 6)
-
reverse(dq3.begin(),dq2.end());//sort list3 in desending order.
-
*/
1 3377 sicarie 4,677
Recognized Expert Moderator Specialist
Can anyone help me with this program?
Look at the bottom of this program for help methods: - /*1. Make a program that uses numbers from 1 to 100 including each ends which puts the even integers in the front of a double linked queue and the odd numbers in the back. Then prints out the deque.
-
-
2. Make a new deque list 2 that contain integers from 51 to 100. Print that list out as mine looks. Sort that list in decending order then print it out and keep the list less than 61 characters per line when you print it out.
-
3. Declare a new deque list 3 then use the resize() method to make it big enough to hold both list 1 and list 2 Next put list 1 in front of list 3 so it is
-
in accending order and put list 2 in the back of list 3 in the decending order.
-
4. Print list 3 out making sure you print only 60 characters or less on a line.
-
5. Sort list 3 in acending order and print it out and keep it 60 or less characters.
-
-
*/
-
#include <iostream>
-
// Notice I comment out the #include list.
-
//#include <list>
-
//#include algorithm has the merge and sort methods
-
#include <algorithm>
-
//deque means double link list
-
#include <deque>
-
-
using namespace std;
-
-
template<class T>
-
void printDeque(const deque<T>& lst, char *s) {
-
cout <<"The list is "<< s << ":"<< endl << endl;
-
int j = 0, k=0;
-
typename deque<T>::const_iterator i = lst.begin();
-
for ( ; i != lst.end(); i++)
-
{
-
//put your code here
-
}
-
-
-
int main() {
-
deque<int> dq1;
-
int i;
-
cout << " \n\n******This is your happy programming day working with Quiz 2!!!!!!!! "<< endl;
-
cout << " \n\nMake a program that uses numbers "<< endl;
-
cout << "from 1 to 100 including each 1 and 100 which puts the odd integers "<< endl;
-
cout << "in the front of a double linked queue and the even numbers in the back."<< endl;
-
cout << "Then prints out the deque. " <<endl;
-
cout << "You can also use the .cpp file attached to start your program." ;
-
cout << endl <<endl;
-
-
-
-
-
system("pause");
-
-
return 0;
-
} // End main()
-
-
-
/*
-
dq1.push_front(2); // dq1 = (2 1)
-
dq1.push_back(3); // dq1 = (2 1 3)
-
dq1.push_back(4); // dq1 = (2 1 3 4)
-
printDeque(dq1,"dq1");
-
deque<int> dq2(dq1.begin()+1,dq1.end()-1); //Jumps to second term and drops
-
printDeque(dq2,"dq2"); // dq2 = (1 3) // back one from the end
-
dq1[1] = 5;
-
printDeque(dq1,"dq1"); // dq1 = (2 5 3 4)
-
dq1.erase(dq1.begin());
-
printDeque(dq1,"dq1"); // dq1 = (5 3 4)
-
dq1.insert(dq1.end()-1,2,6);
-
printDeque(dq1,"dq1"); // dq1 = (5 3 6 6 4)
-
sort(dq1.begin(),dq1.end());
-
printDeque(dq1,"dq1"); // dq1 = (3 4 5 6 6)
-
deque<int> dq3;
-
dq3.resize(dq1.size()+dq2.size());
-
printDeque(dq3,"dq3"); // dq3 = (0 0 0 0 0 0 0)
-
merge(dq1.begin(),dq1.end(),dq2.begin(),dq2.end(),dq3.begin());
-
// dq1 = (3 4 5 6 6) and dq2 = (1 3) ==> dq3 = (1 3 3 4 5 6 6)
-
printDeque(dq1,"dq1"); // dq1 = (3 4 5 6 6)
-
printDeque(dq2,"dq2"); // dq2 = (1 3)
-
printDeque(dq3,"dq3"); // dq3 = (1 3 3 4 5 6 6)
-
reverse(dq3.begin(),dq2.end());//sort list3 in desending order.
-
*/
What do you need help on?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: newsock |
last post by:
What differences between queue, deque and priority_queue? And under what
situations choose one of them to use? Thanks for your help!
|
by: Jenny |
last post by:
Hi,
I have a class foo which will construct some objects in my code. some
of the objects store int values into the data deque, while others
store float values to the deque.
template <class TYPE>
class foo
{
protected:
|
by: Andy |
last post by:
Hi,
I am trying to get the iterator that points to the last element of a
deque.
However, the following program is incorrect:
#include <deque>
#include <iostream>
using namespace std;
|
by: Dan Trowbridge |
last post by:
He everyone,
I am just getting started with .NET and I am having a porting problem.
I get and error in code that lookssomething like this (really stripped down
but you get the idea)...
class dt
{
std::deque< class dt > dtdq;
};
|
by: Russell Warren |
last post by:
Does anyone have an easier/faster/better way of popping from the middle
of a deque than this?
class mydeque(deque):
def popmiddle(self, pos):
self.rotate(-pos)
ret = self.popleft()
self.rotate(pos)
return ret
| |
by: yancheng.cheok |
last post by:
after reading http://www.codeproject.com/vcpp/stl/vector_vs_deque.asp,
i realize that deque has its own speed advantage over vector in all the
aspect (except for memory deallocation). does it mean that we should
prefer deque over vector? (in contrast with c++ standard, which
recommence vector over deque)
thanks!
|
by: Juha Nieminen |
last post by:
I'm sure this is not a new idea, but I have never heard about it
before. I'm wondering if this could work:
Assume that you have a common base class and a bunch of classes
derived from it, and you want to make a deque which can contain any
objects of any of those types. Normally what you would have to do is to
make a deque or vector of pointers of the base class type and then
allocate each object dynamically with 'new' and store the...
|
by: Donos |
last post by:
Hello
I have the following declaration in my code,
******************************************************************
struct mHandleObj
{
HANDLE h;
};
|
by: slizorn |
last post by:
hi guys, another problem i am facing with this program.. i have created a method to read in values from a file and store them into TreeNodes of a Tree
please help me to solve the problem below.. thanks :)
any help/suggestion is appreciated..
the program crashes when it reaches the following line:
assign1 = searchTree(treeObj->root ,data1)->item;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |