int max_elm = 10;
/*element info's structure*/
struct tElmInfo {
int InfoA;
int InfoB;
/*another needed info goes here*/
}
/*List structure*/
struct tList {
int Head;
int Tail; /* if needed */
int count;
tElmInfo Elm[max_elm]; /*we assume that 0 elm won't be used*/
}
void main() {
/*List Var*/
tList List1;
createList(List1);
/*it depends your needs*/
}
void createList(tList *List){
/* we assume that if head and tail point 0, then the list is empty */
(*List).Head = 0;
(*List).Tail = 0;
}
int isEmpty(tList List) {
if ((List.Head == 0) && (List.Tail == 0)) {
return 1;
} else {
return 0;
}
}
int isFull(tList List) {
if (List.count >= max_elm - 1) {
return 1;
} else {
return 0;
}
}
void insertLast(tList *List, tElmInfo X) {
if isFull((*List)) {
printf("List is FULL");
} else {
if isEmpty((*List)) {
(*List).Head = 1;
(*List).Tail = 1;
} else {
(*List).Tail++;
if ((*List).Tail >= max_elm) {
(*List).Tail = 1;
}
}
(*List).Elm[(*List).Tail] = X;
(*List).count++;
}
}
/* for other insert method (like insert first) just modify from code above (i'm sure you can do this) */
tElmInfo delFirst (tList *List) {
tElminfo tmpResult;
if (isEmpty((*List))) { /* actually you do this checking before call this function */
printf("List empty!");
} else {
tmpResult = (*List).element[(*List).Head];
(*List).count--;
if ((*List).Head == (*List).Tail) {
createList(List);
} else {
(*List).Head++;
}
if ((*List).Head >= max_elm) {
(*List).Head = 1;
}
return tmpResult;
}
}
I hope these will help. And I am sorry if there's ('re) mistake(s). There also a lot of other method out there. But the concept always be the same.