Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Doubly linked lists?

the_shrubbthe_shrubb Member Posts: 6
I'm trying to write a doubly linked list, and it's giving me trouble. I can't seem to figure out what's wrong with this code.

using namespace std;
#include "Player.h"
#include "Node.h"
#include "Game.h"

void Game::createGame(int s) {
Node *prev;
Node *start;
Node *beginning;

Player user("User", s);
Player player1("Player1", s);
Player player2("Player2", s);
Player player3("Player3", s);
Player player4("Player4", s);
Player player5("Player5", s);

start = new Node(user);
prev = start;
beginning = start;
start = 0;
start = new Node(player1);
start->llink = prev;
prev->rlink = start;
start = 0;
start = new Node(player2);
start->llink = prev;
prev->rlink = start;
start = 0;
start = new Node(player3);
start->llink = prev;
prev->rlink = start;
start = 0;
start = new Node(player4);
start->llink = prev;
prev->rlink = start;
start = 0;
start = new Node(player5);
start->llink = prev;
prev->rlink = start;
start->rlink = beginning;
beginning->llink = start;
current = beginning;


void Game::stepIt(int s) {
if (s == 0) current->rlink = current;
if (s == 1) current->llink = current;

void Game::eliminate() {


Keep in mind that current is a node pointer declared in my Game.h function. Game is obviously a class. I'm also aware of the sheer inneficiency of this code, but I'll get it working first, and clean it up later.

This is about the fifth variation of my linked list code, and I still can't make it work. Any help?


  • SteveCSteveC Member Posts: 63
    Why not create a list class - containing head/tail pointers to Node, and a few functions to
    - initialise
    - insert
    - delete
    - find
    Nodes within that linked list

    At the moment, you've got a bunch of inline next/prev assignments and it's not going anywhere.

  • Andre YoungAndre Young USAMember Posts: 0

    ___ | | free video tutorials and ebooks about ( Swift, Scratch, Go, Visual Basic .NET, Perl, C++, JavaScript, PL/SQL, C#, Java, Delphi, C, Assembly, Ruby, Visual Basic, PHP, Python, R, MATLAB, Objective-C Erlang, Clojure, F#, ML, Dart, Kotlin, Hack, Apex, FoxPro, D, Scheme, LabVIEW, Lisp, Ada, Lua, Transact-SQL, VBScript, Scala, Julia, Fortran, ABAP, Crystal, COBOL, Alice, Logo, SAS, Prolog, Awk, Bash, Rust ) _________

Sign In or Register to comment.