I started to learn data structures. How can I improve my implementation? For example, I don't now how to push 0
or how to realize my own resize
.
public class Stack: IStack
{
private int[] s;
public Stack(int N)
{
s = new int[N];
}
public void push(int x)
{
int i = 0;
while (s[i] != 0)
{
++i;
}
if (i+1 >= s.Length)
{
Array.Resize(ref s, s.Length*2);
}
s[i] = x;
}
public int pop()
{
int i = 0;
while (i != s.Length && s[i] != 0)
{
i++;
}
s[i] = 0;
return s[i - 1];
}
}
I started to learn data structures. How can I improve my implementation? For example I don't now how to push 0
or how to realize my own resize
?