I'm writing a doubly linked list and a lot of the code ends up being the same with _next and _prev switched. What can I do to keep from writing some code with _next and then the same code again with _prev? Can I do like a template that flips the meaning of the pointers or something?
Hamrick
150
Posting Whiz
Recommended Answers
Jump to PostI can think of one way which would involve both _next and _prev being stored in an array, size 2.
The idea being that they're indexed by a boolean value, so that you can "flip" between the two. Your indexes might be node::pointer[true] for _next, and node::pointer[false] for _prev
…
All 3 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.