Beispiel #1
0
void create_link(link *head)
{
    (*head) = (link)malloc(sizeof(struct node));
    is_malloc(*head);
    (*head)->num = -1;
    (*head)->next = *head;
}
Beispiel #2
0
void			free(void *ptr)
{
  t_block_descriptor	*temp;

  if (ptr == NULL)
    return ;
  temp = (t_block_descriptor *) ptr - 1;
  if (check_chunk(temp) == -1)
    {
      my_put_error("in free(): warning: modified (chunk-) pointer\n");
      return ;
    }
  if (is_already_free(buckets[temp->p - 1], temp) == -1)
    {
      my_put_error("in free(): warning: page is already free\n");
      return ;
    }
    if (is_malloc(temp, 1) == -1)
    {
      my_put_error("in free(): warning: malloc() has never been called\n");
      return ;
    }
  ret_from_list(temp);
  put_in_freelist(temp);
  return ;
}
Beispiel #3
0
int main()
{
    link head;   
    
    create_link(&head);
    
    link newnode;
    
    int i;
    
    for(i = 0; i< 10; i++)
    {
        newnode = (link)malloc(sizeof(struct node));
        
        is_malloc(newnode);

	newnode->num = i + 1;
	
	insert_head_link(&head,newnode);
        //insert_tail_link(&head,newnode);
    }
    
    delete_link(&head,10);
    
    #if 1
    newnode = (link)malloc(sizeof(struct node));

    is_malloc(newnode);

    newnode->num = 11;
    
    insert_mid_link(&head,newnode);

    //inversion_link(&head);
    #endif

    dispaly_link(&head);
    
    return 0;
}
Beispiel #4
0
int pop_link_queue(Link_queue *my_link_queue)
{
    Link p;
    p = (Link)malloc(sizeof(struct link));
    is_malloc(p);

    if(is_empty_queue(my_link_queue) == EMPTY_OK)
    {
        return POP_NO;
    }
    
    p = my_link_queue->front;
    my_link_queue->front = my_link_queue->front->next;

    return p->queue;
}
Beispiel #5
0
void push_link_queue(Link_queue *my_link_queue, int num)
{
    
    Link p;
    
    p = (Link)malloc(sizeof(struct link));
    is_malloc(p);
    
    p->queue = num;

    if(my_link_queue->rear == NULL)
    {
        my_link_queue->rear = p;
        my_link_queue->front = p;
	p->next = NULL;
    }

    my_link_queue->rear->next = p;
    p->next = NULL;
    my_link_queue->rear = p;

}