Example #1
0
File: skew.c Project: minicz/SimLua
static int skew_retrieve (lua_State *L) { /* delete */
  heap *h = checkheap(L, 1);
  heap *h3; /* output heap */
  heap *y1, *y2; /* current nodes on the major and minor paths */
  heap *x; /* next node to be added to the output heap */
  lua_settop(L, 1);
  if (h == NULL) {
    lua_pushnil(L); lua_pushnil(L);
    return 3;
  }
  y1 = h->up; y2 = h->down;
  if (y1->value < y2->value) {
    x = y1; y1 = y2; y2 = x; /* y1 <-> y2 */
  }
  if (y1 == h) {
    pushheap(L, NULL); /* h = NULL */
    pushvaluekey(L, y1);
    delheap(L, h);
    return 3;
  }
  /* initialize h3 to hold y1 */
  h3 = y1; y1 = y1->up; h3->up = h3;
  while (1) {
    if (y1->value < y2->value) {
      x = y1; y1 = y2; y2 = x; /* y1 <-> y2 */
    }
    if (y1 == h) {
      pushheap(L, h3); /* h = h3 */
      pushvaluekey(L, y1);
      delheap(L, h);
      return 3;
    }
    /* remove x == y1 from its path */
    x = y1; y1 = y1->up;
    /* add x to the top of h3 and swap its children */
    x->up = x->down; x->down = h3->up; h3->up = x; h3 = h3->up;
  }
}
Example #2
0
heapsort(){

    printf("Enter the value of num \n");
    scanf("%d",&num);
    heapArray[0]=num;

    printf("enter the values one by one \n");
    for(i=1;i<=num;i++){
        scanf("%d",&heapArray[i]);
    }
    makeheap(heapArray);

    for(i=1;i<=num;i++){
        printf("%d ",heapArray[i]);
    }
    printf("\n");

    while(heapArray[0]>0){
        printf("%d",delheap(heapArray));
       // printf("\n");
//        delheap(heapArray);
    }
    return(0);
}