I could copy the same thing over here, or I could link to the same question i already created.. It's a simple link man. It took you longer to write a spiteful message than click it.
It takes someone longer to complain about bad breath than it does to ignore it.
I looked at your code - you seem to have a design flaw. A linked-list doesn't use instances of itself as nodes, at least not the last time I checked. You need a node class. You also have private data members marked as public.
it is public because it can be, and it's easier that way, not because it is best practice.
If you do not want to use best practice then why are you asking for help from people who do? That's like asking how to make your breath smell better but you don't want to brush your teeth twice a day.
spyro wrote:
the linkedlist is the node class. I was taught to link it to other nodes (previous and next) which is what I (thought) I did.
It doesn't make sense to have the linked list also be a single node. Normally a nested helper node class is used by linked list classes:
1 2 3 4 5 6 7 8 9 10
template<typename T>
class MyLinkedList
{
struct Node
{
T data;
Node *prev, next;
};
//...
};
alright, I guess I see what you're saying. i guess I didn't see why it was necessary to use a structure for it. You could use a structure and skip the class aslltogether if you wanted. I was using the class for nodes.
I suppose this is a design flaw, but it should still work I'd think? I am buried in other classes right now. I'm trying to finish this program, but I don't think I have time to redo the entire thing. It should still work, even if it is stupidly coded. I don't know why I'm getting those errors
OK. Some of your errors are because of malformed syntax:
1 2 3 4 5 6 7 8 9 10
//overloaded ++ operator to call editPos and set the pos to the next element (pos->next)
doubleLinkedList::doublelinkedList*.operator++() //should be <return> <class>::operator<op>()
{
head->editPos(doubleLinkedList* pos->next);
}
//same as above but previous.
doubleLinkedList::doublelinkedList* operator--()//should be <return> <class>::operator<op>()
{
head->editPos(doubleLinkedList* pos->previous);
}
pos is a pointer to a DLL, so i need a pointer as a parameter to change it, but it says "type name not allowed"
lol, the more i look at the code, the more terrible it looks.. Why am I using head as an index for pos? Anyway.. I don't know the problem.
Also..
and each of the following lines say this declaration has no storage class or type specifier"
tail->data = 1;
tail->previous = nullptr;
head = tail;
pos is a pointer to a DLL, so i need a pointer as a parameter to change it, but it says "type name not allowed"
lol, the more i look at the code, the more terrible it looks.. Why am I using head as an index for pos? Anyway.. I don't know the problem.
Remove the type "doubleLinkedList*" from the function call - you are calling a function, not declaring it ;)
spyro wrote:
Also..
and each of the following lines say this declaration has no storage class or type specifier"
1 2 3
tail->data = 1;
tail->previous = nullptr;
head = tail;
39 40 41 42 43 44 45 46 47
//global use
//Head is start, following null. tail is end, proceeding null.
doubleLinkedList* tail; = new doubleLinkedList;
doubleLinkedList* head;
//initialize the list globally so other functions can use head and tail.
tail->data = 1;
tail->previous = nullptr;
head = tail;
head->editPos(doubleLinkedList* head);
You can't have program statements in the global scope. What are these supposed to do anyway? They're not associated with any instance of the class - did you mean to put this in the constructor?
I thought functions needed type names in parameters in a function call in c++.. hmm.. I've never used c before, just flash actionscript lol
I'm not gonna deny my code is terrible, Ill just try to explain my terrible logic: for some reason, I decided to use the same head and tail throughout the code for indexes and whatnot, so I needed access from a global scope.
I suppose the only fix is to alter the class so the nodes are a structure then add head and tail to the class.
Not at present, because head and tail are used throughout list.cpp under the assumption that all the lists (nodes) are using the same head and tail. if I put it in my class, each node would have a different one.
this is why the nested structure is what should be done. becaus then head/tail would be outside the node structure, and I would use one object per list.. but alas, I think I figured out how to fix thing now. Appreciate the help. :)