Linked List HELP!!

Hi! I'm making a linked list where it contains 6 elements and wherein if i roll a dice, starting from the first element, going to the element according to the roll. And then I will roll again but this time, I will start from the element where I stopped from the previous roll.

So if your initial state is 1->2->3->4->5->6 and you roll a 4, you advance to 4.
But if the next roll is a 3, I would circle back to the 1.

I'm basically new to data structure programming :( Help is appreciated.

Sorry for my bad english! Thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  // C++ program to find n'th  
// node in linked list  
#include <bits/stdc++.h> 
#include <assert.h>  
#include <stdlib.h>        
using namespace std; 
  
// Link list node  
class Node  
{  
    public: 
    int data;  
    Node* next;  
};  
  
/* Given a reference (pointer to  
pointer) to the head of a list  
and an int, push a new node on  
the front of the list. */
void push(Node** head_ref, int new_data)  
{  
      
    // allocate node  
    Node* new_node = new Node(); 
  
    // put in the data  
    new_node->data = new_data;  
  
    // link the old list  
    // off the new node  
    new_node->next = (*head_ref);  
  
    // move the head to point  
    // to the new node  
    (*head_ref) = new_node;  
}  
  
// Takes head pointer of  
// the linked list and index  
// as arguments and return  
// data at index  
int GetNth(Node* head, int index)  
{  
      
    Node* current = head;  
      
    // the index of the  
    // node we're currently  
    // looking at  
    int count = 0;  
    while (current != NULL)  
    {  
        if (count == index)  
            return(current->data);  
        count++;  
        current = current->next;  
    }  
  
    /* if we get to this line,  
    the caller was asking  
    for a non-existent element  
    so we assert fail */
    assert(0);          
}  
  
// Driver Code  
int main()  
{  
      
    // Start with the  
    // empty list  
    Node* head = NULL;  
  
    // Use push() to construct  
    // below list  
    // 1->2->3->4->5->6
    push(&head, 6);
    push(&head, 5);  
    push(&head, 4);  
    push(&head, 3);  
    push(&head, 2);  
    push(&head, 1);  
  
    int dice;
    dice = rand() % 6 + 1;
    cout << "The dice is: " << dice; 
    if(dice == 1)
    {
    	
	}
	else if(dice == 2)
	{
		
	}
	else if(dice == 3)
	{
		
	}
	else if(dice == 4)
	{
		
	}
	else if(dice == 5)
	{
		
	}
	else if(dice == 6)
	{
		
	}
    
    return 0;
}  
Last edited on
> would circle back to the 1.
then perhaps you should make a circular linked list
having a tail pointer will help with that
@ne555

can you help me with the code?
Topic archived. No new replies allowed.