- #1
Avichal
- 295
- 0
I decided to make a library for some common data structures and I'm facing some design problems.
I wanted to implement linked list using classes in c++.
Here is the sample class:-
I want the next pointer to point to another Linked_List class. Current class should store key and pointer to next class.
Problem with this design:
1) In constructor I have to give the first key. I can't have a class with no key.
2) When I need to insert a key before the first one, then it involves deleting the "this" pointer but that's not possible.
Any better design for a linked list class? (some standard implementation)?
I wanted to implement linked list using classes in c++.
Here is the sample class:-
Code:
class Linked_List
{
private:
int key;
Linked_List* next;
public:
Linked_List(int key)
{
this->key = key;
this->next = NULL;
}
void insert(int key)
{
...
}
void delete(int key)
{
...
}
}
I want the next pointer to point to another Linked_List class. Current class should store key and pointer to next class.
Problem with this design:
1) In constructor I have to give the first key. I can't have a class with no key.
2) When I need to insert a key before the first one, then it involves deleting the "this" pointer but that's not possible.
Any better design for a linked list class? (some standard implementation)?