Array-Based Implementation of Linked Lists

I first want to say that i am trying to solve my code without Pointers.

My goal is to..
1. Construct an empty 2D array with a capacity of 25. (list[25][2];)
2. Empty(): test if the stack is empty
3. Push(): add a value to the stack in the (list[i][0] = value;) position and (list[i][1] = previous list[i][0] position)
4. Top(); read the value(list[i][0]) at the top(count) of the stack
5. Pop(); remove the value at the top of the stack (list[i]= 0;)
6. Display(); displays all the elements in the stack going from the top to bottom order. (shows array index, data value, and next array index)

I have hit a road block and don't know what to fix or where to go from here.

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

#include <iostream>
#include <cstdlib>
#include <ctime>


using namespace std;

char name[5];

srand(time(0));




//Protoypes
void construction(int table[25][2]);
void empty();
void push(int value, int& next, int& count);
void top();
void pop(int& count, int& top);
void display();


int main()
{
	int list[25][2];
	int next = -1;
	int count = 0;

	push(1, next, count);
	push(2, next, count);
	push(3, next, count);
	push(4, next, count);
	push(5, next, count);
	push(6, next, count);
	push(7, next, count);
	push(8, next, count);
	push(9, next, count);
	push(10, next, count);

	display();

	push(20, next, count);
	display();
	push(30, next, count);
	display();
	push(40, next, count);
	display();

	top();
	pop();
	display();

	top();
	pop();
	display();

	top();
	pop();
	display();

	return 0;


}


//Stubs


void empty()
{
	if (count == 0)
		cout << "The stack is empty.";
	else
		cout << "The stack is not empty.";
}

void push(int value, int& next , int& count)
{
	int i = 0;
	int k = 0;
	bool duplicate = false;

	srand(time(0));


	do
	{
		
		i = rand() % 25;

		if(list[i][0] == 0 )
		{
			duplicate = false;
			list[i][0] = value;
			count += 1;

			if(count == 0)
			{
				list[i][1] = -1;
			}

			else if(count > 0)
			{
				list[i][1] = next;
			}
		}

		else if(list[i][0] != 0)
		{
			duplicate = true;	
		}
	

	}while(duplicate == true);

	

}

void top()
{
	if (myTop != -1)
		cout << "The top of stack value is: " << L[myTop];
	else
		cout << "The stack is empty.";
	cout << endl;
}

void pop(int& count, int& top)
{
	if (count != 0)
	{
		list[top][0] = 0;
		
	}
		
}

void display()
{
	for (int row=0; row<25; row++)
	{
		for (int column=0; column < 2; column++)
		{
			cout << list[row][column] << "\n";
		}
	}
	cout << endl;
}

> what to fix or where to go from here.
¿is there a problem?


1
2
void pop(int& count, int& top);
pop();
for starter, you may want to stop lying.
Topic archived. No new replies allowed.