also, error is at the line "list.hdr =(list *) malloc(sizeof(struct SkipList));" is the size allocation here is correct or it should be diffrent.
code:
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include <stdlib.h>
- #define compLT(a,b) (a < b)
- #define compEQ(a,b) (a == b)
- #define MAXLEVEL 15
- // levels range from (0 .. MAXLEVEL)
- struct Node_ {
- int data;
- struct Node_ *forward[1];
- } Node;
- struct SkipList{
- struct Node_ *hdr; // list Header
- int listLevel; // current level of list
- }list;
- <snipped>
- // initialize skip list
- int initList()
- {
- int i;
- list.hdr =(list *) malloc(sizeof(struct SkipList));
- for (i = 0; i <= MAXLEVEL; i++)
- list.hdr->forward[i] = list.hdr;
- list.listLevel = 0;
- printf("\nskip initialized");
- printf("\ninitial current level of list=%d",list.listLevel);
- printf("\ninitial skip is empty and all hdr pointer=list.hdr");
- }