473,387 Members | 1,550 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,387 software developers and data experts.

Clueless to this C++ programming and need all the help i can get!!!!

4
I am trying to do a C++ program but have no idea what i am doing HELP HELP HELP!!!

Instructions

On your textbook page 92, Figure 3.10 shows code for a generic doubly linked list. However, our textbook does not show all the DoublyLinkedList member functions. So, we should define all the missing member functions. Textbook shows two member functions – addToDLLTail( ) and deleteFromDLLTail( ). The missing member functions are addToDLLHead( ), deleteFromDLLHead( ), and deleteDLLNode( ).

To complete this job, I will take deleteDLLNode( ), and you will complete addToDLLHead( ) and deleteFromDLLHead( ). To make your life a little easier, I add a HW6-template.CPP, which has all the code already written except ones for addToDLLHead and deleteFromDLLHead. Download this file and fill out the code for both member functions. This is a generic class, so study the existing code carefully how template <class T> is handled.

- Note that DLLNode now has two pointers - *next and *prev. So, when you write a code, you must consider values of both pointers.

and here is the program from the book.

Expand|Select|Wrap|Line Numbers
  1. #ifndef DOUBLY_LINKED_LIST
  2. #define DOUBLY_LINKED_LIST
  3. template<class T>
  4. class DLLNode {
  5. public:
  6.     DLLNode() {
  7.         next = prev = 0;
  8.     }
  9.     DLLNode(const T& el, DLLNode *n = 0, DLLNode *p = 0) {
  10.         info = el; next = n; prev = p;
  11.     }
  12.     T info;
  13.     DLLNode *next, *prev;
  14. };
  15. template<class T>
  16. class DoublyLinkedList {
  17. public:
  18.     DoublyLinkedList() {
  19.         head = tail = 0;
  20.     }
  21.     void addToDLLTail(const T&);
  22.     T deleteFromDLLTail();
  23.     . . . . . . . . . . . . .
  24. protected:
  25.     DLLNode<T> *head, *tail;
  26. };
  27. template<class T>
  28. void DoublyLinkedList<T>::addToDLLTail(const T& el) {
  29.     if (tail != 0) {
  30.          tail = new DLLNode<T>(el,0,tail);
  31.          tail->prev->next = tail;
  32.     }
  33.     else head = tail = new DLLNode<T>(el);
  34. }
  35. template<class T>
  36. T DoublyLinkedList<T>::deleteFromDLLTail() {
  37.     T el = tail->info;
  38.     if (head == tail) { // if only one node in the list;
  39.          delete head;
  40.          head = tail = 0;
  41.     }
  42.     else {              // if more than one node in the list;
  43.          tail = tail->prev;
  44.          delete tail->next;
  45.          tail->next = 0;
  46.     }
  47.     return el;
  48. }
  49. . . . . . . . . . . . . .
  50. #endif
How do i do all of that from the instructions please help i feel so stupid i do not know what im doing!!!!! Feel stupid!!!
Aug 15 '13 #1
6 1167
weaknessforcats
9,208 Expert Mod 8TB
Watch this video first: http://www.youtube.com/watch?v=9bX9WaIVyAg

This will explain the concept.

I assume you are all right with templates and it's just the linked list concept that is confusing.
Aug 15 '13 #2
odlaw
4
@weaknessforcats
thanks for the link, and help i appreciate it. i just feel out of my league with this stuff. what is confusing me i think is the addToDLLHead and deleteFromDLLHead code i still do not fully understand how to do it or what goes in these areas.
Aug 16 '13 #3
weaknessforcats
9,208 Expert Mod 8TB
When you delete from the head of a linked list, the second node becomes the first node. So all you do is go to the first node and take the address inside the next pointer of that note and make it the first node in DoublyLinkedLIst.

You now have removed the original first node from the list. Hopefully you have saved the original first pointer in DoublyLinkedList so you can delete the pointer.

To delete from the tail you take the prev pointer in the tail and go the prev node. You make the next pointer in the prev node zero. Then you go to DoublyLinkedList and set the tail pointer to the address that was in the prev node of the original tail. You can now delete the original tail node.

I usually see deleting from the head, tail, or middle of a list all done by the same DoublyLinkedList member function. This function takes a node pointer as an argument and it tests the prev pointer of the node to be deleted and if it is zero, then there is no previous node making this a delete from the head. Likewise, a zero in the next pointer makes thie is delete from tail. Otherwise, it is a delete from the middle.

The DoublyLinkedList delete would call a Node member function to work out the prev/next values since DoublyLinkedList cannot see these private members of Node.

Done correctly, there will be only 5 lines of code in the entire program that will use the next/prev variables and these lines will be in a private Node member function that is called only by other Node member functions that need to adjust these values.
Aug 16 '13 #4
odlaw
4
thanks again for responding you make it sound simple. but i still just cant figure it all out. i wish i had never started this class its too late to drop and if i get a failing grade im in for it. im still probably going to flunk cause i just dont know where or what to do or begin and keep hitting myself for ever starting this.
Aug 16 '13 #5
weaknessforcats
9,208 Expert Mod 8TB
Probably you understand more than you think. Just keep at it. A linked list is a fundamental concept that is used in all sorts of places where you least expect it.

The first time you take one of these C++ courses your retention might only be 10%. However, the next time you encounter these concepts your retention might increase to 20%. Eventually, it all makes sense. I used to tell my beginning students that learning C++ was like making Chinese lacquered furniture: 45 applications of lacquer later, you were done.

You sound exactly like me when I started in 1990.
Aug 16 '13 #6
odlaw
4
i thank you again for everything you have done to help me. this class will be over soon and i wont have to worry about it any more. it has been getting progressively worse and its only 5 weeks they are trying to push so much into that 5 weeks. online learning is a good thing, but when it comes to things like this i think they need to try to stretch it out for people who just cant get the hang of it. if you know what i mean. IF i pass it will be by the skin of my teeth.
Aug 17 '13 #7

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

Similar topics

34
by: Volker Hetzer | last post by:
Hi! I've done lots of programming for CAD, which was basically C/C++ and tcl/tk. Now, we are thinking about introducing more web based tools, programming them ourselves and right now the toolchain...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
2
by: Peter | last post by:
Hi, everybody I'm coding a windows application. My computer works in an intranet and it will save datas into a MS Access DB every day. Some time I need report some datas in my Access DB to the...
9
by: xparrot1 | last post by:
I know that I can get the SERVER port number like this: HttpContext.Current.Request.ServerVariables My question is how do I get the remote CLIENT port number? Thanks Derek
102
by: BoogieWithStu22 | last post by:
I am running into a problem with a web page I have created when viewing it in IE6 on some machines. The page has a database lookup. The user enters an account name or number and clicks a lookup...
1
by: byquestion | last post by:
Hi there xslt gurus, i am kinda new to xslt and having difficulty to implement my some iterations. i need to recreate an xml file by using xslt. here is the sample xml file(input for xslt) ...
1
by: mehedul | last post by:
i want to be JAVA programmar. i have enough hope and i want to do enough labouring. give me guideline to develop me.
0
by: latha ranjani | last post by:
Hi, i am new to .Net programming,need your help in solving this issue. I have open a word document capture the pagesetup properties of the word document and then open a new word document with the...
0
by: daryl | last post by:
<code> <body> <h1>Reverse String</h1><hr /> <?php $ReverseString = $_GET; if (!isset($_GET)) echo "<p>Enter the string you want to reverse.</p>"; else{ $ForwardString = $$_GET; ...
2
by: kash072 | last post by:
Dudes, this is my second post. In the first post i got very good help and guidance. Hoping the same, i going for this new thread - CyberSoftHari had suggested to go for some betting projects and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.