473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program with deque using Visual C++

1 New Member
Can anyone help me with this program?

Look at the bottom of this program for help methods:


Expand|Select|Wrap|Line Numbers
  1. /*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.  
  3. 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.
  4. 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
  5. in accending order and put list 2 in the back of list 3 in the decending order.
  6. 4. Print list 3 out making sure you print only 60 characters or less on a line.
  7. 5. Sort list 3 in acending order and print it out and keep    it 60 or less characters.
  8.  
  9. */
  10. #include <iostream>
  11. // Notice I comment out the #include list.
  12. //#include <list>
  13. //#include algorithm has the merge and sort methods
  14. #include <algorithm>
  15. //deque means double link list
  16. #include <deque>
  17.  
  18. using namespace std;
  19.  
  20. template<class T>
  21. void printDeque(const deque<T>& lst, char *s) {
  22.     cout <<"The list is "<< s << ":"<< endl << endl;
  23.      int j = 0, k=0;
  24.     typename deque<T>::const_iterator i = lst.begin(); 
  25.     for ( ; i != lst.end(); i++)
  26.      {
  27.          //put your code here
  28.      }
  29.  
  30.  
  31. int main() {
  32.     deque<int> dq1;
  33.      int i;
  34.      cout << " \n\n******This is your happy programming day working with Quiz 2!!!!!!!! "<< endl;
  35.     cout << " \n\nMake a program that uses numbers "<< endl;
  36.     cout << "from 1 to 100 including each 1 and 100 which puts the odd integers "<< endl;
  37.     cout << "in the front of a double linked queue and the even numbers in the back."<< endl;
  38.     cout << "Then prints out the deque. " <<endl;    
  39.     cout << "You can also use the .cpp file attached to start your program." ; 
  40.     cout << endl <<endl;
  41.  
  42.  
  43.  
  44.  
  45.     system("pause");
  46.  
  47.     return 0;
  48. } // End main()
  49.  
  50.  
  51. /*
  52.     dq1.push_front(2);         // dq1 = (2 1)
  53.     dq1.push_back(3);          // dq1 = (2 1 3)
  54.     dq1.push_back(4);          // dq1 = (2 1 3 4)
  55.     printDeque(dq1,"dq1");
  56.     deque<int> dq2(dq1.begin()+1,dq1.end()-1); //Jumps to second term and drops
  57.     printDeque(dq2,"dq2");     // dq2 = (1 3)  //  back one from the end
  58.     dq1[1] = 5;
  59.     printDeque(dq1,"dq1");     // dq1 = (2 5 3 4)
  60.     dq1.erase(dq1.begin()); 
  61.     printDeque(dq1,"dq1");     // dq1 = (5 3 4)
  62.     dq1.insert(dq1.end()-1,2,6);
  63.     printDeque(dq1,"dq1");     // dq1 = (5 3 6 6 4)
  64.     sort(dq1.begin(),dq1.end()); 
  65.     printDeque(dq1,"dq1");     // dq1 = (3 4 5 6 6)
  66.     deque<int> dq3;
  67.     dq3.resize(dq1.size()+dq2.size()); 
  68.     printDeque(dq3,"dq3");     // dq3 = (0 0 0 0 0 0 0)
  69.     merge(dq1.begin(),dq1.end(),dq2.begin(),dq2.end(),dq3.begin()); 
  70.     // dq1 = (3 4 5 6 6) and dq2 = (1 3) ==> dq3 = (1 3 3 4 5 6 6)
  71.     printDeque(dq1,"dq1");     // dq1 = (3 4 5 6 6)
  72.     printDeque(dq2,"dq2");     // dq2 = (1 3)
  73.     printDeque(dq3,"dq3");     // dq3 = (1 3 3 4 5 6 6)
  74.     reverse(dq3.begin(),dq2.end());//sort list3 in desending order.
  75.      */
Feb 18 '07 #1
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:


Expand|Select|Wrap|Line Numbers
  1. /*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.  
  3. 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.
  4. 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
  5. in accending order and put list 2 in the back of list 3 in the decending order.
  6. 4. Print list 3 out making sure you print only 60 characters or less on a line.
  7. 5. Sort list 3 in acending order and print it out and keep    it 60 or less characters.
  8.  
  9. */
  10. #include <iostream>
  11. // Notice I comment out the #include list.
  12. //#include <list>
  13. //#include algorithm has the merge and sort methods
  14. #include <algorithm>
  15. //deque means double link list
  16. #include <deque>
  17.  
  18. using namespace std;
  19.  
  20. template<class T>
  21. void printDeque(const deque<T>& lst, char *s) {
  22.     cout <<"The list is "<< s << ":"<< endl << endl;
  23.      int j = 0, k=0;
  24.     typename deque<T>::const_iterator i = lst.begin(); 
  25.     for ( ; i != lst.end(); i++)
  26.      {
  27.          //put your code here
  28.      }
  29.  
  30.  
  31. int main() {
  32.     deque<int> dq1;
  33.      int i;
  34.      cout << " \n\n******This is your happy programming day working with Quiz 2!!!!!!!! "<< endl;
  35.     cout << " \n\nMake a program that uses numbers "<< endl;
  36.     cout << "from 1 to 100 including each 1 and 100 which puts the odd integers "<< endl;
  37.     cout << "in the front of a double linked queue and the even numbers in the back."<< endl;
  38.     cout << "Then prints out the deque. " <<endl;    
  39.     cout << "You can also use the .cpp file attached to start your program." ; 
  40.     cout << endl <<endl;
  41.  
  42.  
  43.  
  44.  
  45.     system("pause");
  46.  
  47.     return 0;
  48. } // End main()
  49.  
  50.  
  51. /*
  52.     dq1.push_front(2);         // dq1 = (2 1)
  53.     dq1.push_back(3);          // dq1 = (2 1 3)
  54.     dq1.push_back(4);          // dq1 = (2 1 3 4)
  55.     printDeque(dq1,"dq1");
  56.     deque<int> dq2(dq1.begin()+1,dq1.end()-1); //Jumps to second term and drops
  57.     printDeque(dq2,"dq2");     // dq2 = (1 3)  //  back one from the end
  58.     dq1[1] = 5;
  59.     printDeque(dq1,"dq1");     // dq1 = (2 5 3 4)
  60.     dq1.erase(dq1.begin()); 
  61.     printDeque(dq1,"dq1");     // dq1 = (5 3 4)
  62.     dq1.insert(dq1.end()-1,2,6);
  63.     printDeque(dq1,"dq1");     // dq1 = (5 3 6 6 4)
  64.     sort(dq1.begin(),dq1.end()); 
  65.     printDeque(dq1,"dq1");     // dq1 = (3 4 5 6 6)
  66.     deque<int> dq3;
  67.     dq3.resize(dq1.size()+dq2.size()); 
  68.     printDeque(dq3,"dq3");     // dq3 = (0 0 0 0 0 0 0)
  69.     merge(dq1.begin(),dq1.end(),dq2.begin(),dq2.end(),dq3.begin()); 
  70.     // dq1 = (3 4 5 6 6) and dq2 = (1 3) ==> dq3 = (1 3 3 4 5 6 6)
  71.     printDeque(dq1,"dq1");     // dq1 = (3 4 5 6 6)
  72.     printDeque(dq2,"dq2");     // dq2 = (1 3)
  73.     printDeque(dq3,"dq3");     // dq3 = (1 3 3 4 5 6 6)
  74.     reverse(dq3.begin(),dq2.end());//sort list3 in desending order.
  75.      */
What do you need help on?
Feb 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
12696
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!
7
4097
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:
4
1139
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;
7
3480
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; };
5
3505
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
5
6159
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!
15
3537
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...
1
2934
by: Donos | last post by:
Hello I have the following declaration in my code, ****************************************************************** struct mHandleObj { HANDLE h; };
2
1565
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;
0
9646
marktang
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...
0
9483
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,...
0
10157
jinu1996
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...
1
10096
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,...
0
8982
agi2029
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...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.