473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Program with deque using Visual C++

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 3346
sicarie
4,677 Expert Mod 4TB
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
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
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...
4
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
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...
5
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()...
5
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...
15
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...
1
by: Donos | last post by:
Hello I have the following declaration in my code, ****************************************************************** struct mHandleObj { HANDLE h; };
2
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.....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.