LinkedList using array?

Hello all! This code is an implementation of contiguous lists, in the main(), I always get the message "List is full",

what should I do?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const int Long=100;
struct List{
int e[Long];
int last;
};
Liste L;
//p is for position
void insertion(int x, int p, Liste &L){
if(L.last>Long-1 ) cout <<"List is Full\n";
else if (p<0 || p>L.last+1) cout <<"P incorrect\n";
else {

    for( int i=L.last; i>p; i--) L.e[i+1]=L.e[i];
    L.last--;
}
 

in the main:
1
2
3
4
5
6
7
 
int main(){
List L; 
// however i don't know how to initialize L.der??
//I Know that L.der will start at -1, since it's empty, 
insertion(10,0,L); 
}
Last edited on
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) You haven't shown us enough code to know what might be happening inside the call to insertion(). In particular, you haven't shown us what the state of L is when you pass it into the function.
Sorry about that, I changed it :)
Thanks for using code tags!

So, from your comment, I can see that you already understand what the problem is - you're not initialising the contents of L.

The best way to do this is to create a constructor for L. The constructor should use an initialisation list to initialise the contents.
Thanks !!
Topic archived. No new replies allowed.