|
I don't know the specifics of your implementation of "LinkedList.h" but here are a couple of quick things to get you started.
You don't ever really "append a node". When you add "7 feet, 2 inches", you are really inserting it (in the middle of your list). You have to find the node you want to add before (just before "8 feet, 9 inches") and then insert your node.
You are inserting distance4 before you create it. You have to create the object first, then insert it.
In your code, you say you are "deleting the last node" but that's not what you are doing. Do are deleting a specific node. To delete the last node, you have to go to the end of the list and then delete that node.
|
|
|
|
|
I'm kind of confused I'm not sure if I know what you mean. I looked in my book and it was the same program and the code in the book.
|
|
|
|
|
Essentially these two lines need to be swapped because you are attempting to insert a variable before it was created.
list.insertNode(distance4);
FeetInches distance4(7, 2);
It is hard to say if there are any other bugs because we cannot see the implementation of LinkedList.h
Best Wishes,
-David Delaune
|
|
|
|
|
What does the implementation of LinkedList look like?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Here is linked list.h Thanks for all the help by the way. Do you need FeetInches.h also
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
using namespace std;
template <class t="">
class LinkedList
{
public:
struct ListNode
{
T value;
struct ListNode *next;
};
ListNode *head;
public:
LinkedList()
{ head = NULL; }
~LinkedList();
void appendNode(T);
void insertNode(T);
void deleteNode(T);
void displayList() const;
};
template <class t="">
void LinkedList<t>::appendNode(T newValue)
{
ListNode *nodePtr;
newNode = new ListNode;
newNode->value = newValue;
newNode->next = NULL;
if (!head)
head = newNode;
else
{
nodePtr = head;
while (nodePtr->next)
nodePtr = nodePtr->next;
nodePtr->next = newNode;
}
}
template <class t="">
void LinkedList<t>::displayList() const
{
ListNode *nodePtr;
nodePtr = head;
while (nodePtr)
{
cout << nodePtr->value << endl;
nodePtr = nodePtr->next;
}
}
template <class t="">
void LinkedList<t>::insertNode(T newValue)
{
ListNode *newNode;
ListNode *nodePtr;
ListNode *previousNode = NULL;
newNode = new ListNode;
newNode->value = newValue;
if (!head)
{
head = newNode;
newNode->next = NULL;
}
else
{
nodePtr = head;
previousNode = NULL;
while (nodePtr != NULL && nodePtr->value < newValue)
{
previousNode = nodePtr;
nodePtr = nodePtr->next;
}
if (previousNode == NULL)
{
newNode->next = nodePtr;
}
else
{
previousNode->next = newNode;
newNode->next = nodePtr;
}
}
}
template <class t="">
void LinkedList<t>::deleteNode(T searchValue)
{
ListNode *nodePtr;
ListNode *previousNode;
if (!head)
return;
if (head->value == searchValue)
{
nodePtr = head->next;
delete head;
head = nodePtr;
}
else
{
nodePtr = head;
while (nodePtr != NULL && nodePtr->value != searchValue)
{
previousNode = nodePtr;
}
if (nodePtr)
{
previousNode->next = nodePtr->next;
delete nodePtr;
}
}
}
template <class t="">
LinkedList<t>::~LinkedList()
{
ListNode *nodePtr;
ListNode *nextNode;
nodePtr = head;
while (nodePtr != NULL)
{
nextNode = nodePtr->next;
delete nodePtr;
nodePtr = nextNode;
}
}
#endif</t></class></t></class></t></class></t></class></t></class></class></iostream>
|
|
|
|
|
Did you heed Randor's advice?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
yes, and i get the following error messages.
linkedlist.h(47) : error C2065: 'newNode' : undeclared identifier
linkedlist.h(43) : while compiling class template member function 'void LinkedList<t>::appendNode(T)'
with
[
T=FeetInches
]
linkedlistexample.cpp(11) : see reference to class template instantiation 'LinkedList<t>' being compiled
with
[
T=FeetInches
]
linkedlist.h(48) : error C2227: left of '->value' must point to class/struct/union/generic type
linkedlist.h(49) : error C2227: left of '->next' must point to class/struct/union/generic type
|
|
|
|
|
LilKoopa wrote: linkedlist.h(47) : error C2065: 'newNode' : undeclared identifier
The error is self explanatory. On line 47 of linkedlist.h, you are using newNode which has not yet been declared.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
ok now I'm down this one error message and i dont know what i am suppossed to do
error C2244: 'LinkedList<t>::displayList' : unable to match function definition to an existing declaration
|
|
|
|
|
LilKoopa wrote:
error C2244: 'LinkedList::displayList' : unable to match function definition to an existing declaration
So which line is causing this error?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
|
Asking a question that includes the code that fails.
Either that, or the time-honoured tradition of debugging.
|
|
|
|
|
MSDN:
------
If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the return value is nonzero, regardless of the translation.
But I'd like to know if there's any way to determine if TranslateMessage() has produced a WM_CHAR, while recieving a WM_KEYDOWN or not. E.g. pressing <home> key produces no WM_CHAR normally; however TranslateMessage() returns nonzero when recieving it! because it's a WM_KEYDOWN any way ...
Thank you masters!
|
|
|
|
|
You could try simply checking if there is a WM_CHAR message in the message queue or not, since afaik that's what TransateMessage does, it places a WM_CHAR into the message queue. So you could try using PeekMessage to check on the queue. Of course this is not a fail-safe method because the queue might have had a WM_CHAR in it already. Maybe you could use the "timestamp" of the message to see if it has been placed into the queue by TranslateMessage or not.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Thank you for reply. I'm gonna take your words.
|
|
|
|
|
i want to know about comport and how it is related with delegates..
can any body help me here..
vikas da
|
|
|
|
|
if you need to access the serial port using C++ then see, for instance, [^]. You may also exploit the Code Project 's article search engine [^].
On the other hand, if you need help on delegates, maybe the C# forum [^] is more appropriate.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
They are completely different things.
It's like asking how a fish is related to space travel. Technically, you could put a tuna on the shuttle, but the two are not related...
What makes you think there may be some relationship? Maybe there is another question hiding under your current one.
Iain.
|
|
|
|
|
Iain Clarke wrote: It's like asking how a fish is related to space travel
Space ships, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I shoulda known you'd find the tenuous link!
Fish'n'Chips...
Fission Ships...
OK, now I'm hungry!
Iain.
|
|
|
|
|
Iain Clarke wrote: It's like asking how a fish is related to space travel. Technically, you could put a tuna on the shuttle, but the two are not related...
That's a good one...
|
|
|
|
|
Well, I only have two quotes in Carlo's quote list. I want to dominate, dammit!
Iain.
|
|
|
|
|
Your quote (the one in my sign) already (and still) dominates the list.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi.
In my app I have an button which is owner draw. The strange thing is happening I can't set it's font?
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
MaliFont.CreateFontIndirect(&ncm.lfMessageFont);
m_Graph.SetFont(&MaliFont);
MaliFont is an CFont member variable.
m_Graph is my button.
To be honest Button ctrl is only a base for my graph ctrl I'm displaying. There is no way I can set font using that graph ctrl, I thought I can set it using base class (CButton).
???
|
|
|
|
|
If your button is owner draw then you have to draw it yourself: I suppose it doesn't make sense changing its font via CButton::SetFont .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|