2018q3 Homework2(lab0)

contributed by < MikeCola >

作業前準備

Visual Studio C 語言調適筆記

C Programming Lab

Overview

/*Linked list element*/ typedef struct ELE { char *value; struct ELE *next; } list_ele_t; /*Queue structure*/ typedef struct { list_ele_t *head; /*Linked list of elements*/ } queue_t;
  • A NULL queue: One for which the pointer has value NULL.
  • An empty queue: One pointing to a valid structure, but the head field has value NULL.

Programming Task

  • q_new: Create a new, empty queue.
  • q_free: Free all storage used by a queue.
  • q_insert_head: Attempt to insert a new element at the head of the queue (LIFO discipline).
  • q_insert_tail: Attempt to insert a new element at the tail of the queue (FIFO discipline).
  • q_remove_head: Attempt to remove the element at the head of the queue.
  • q_size: Compute the number of elements in the queue.
  • q_reverse: Reorder the list so that the queue elements are reversed in order. This function should not allocate or free any list elements (either directly or via calls to other functions that allocate of free list elements.) Instead, it should rearrange the existing elements.

queue.h

/* Queue structure */ typedef struct { list_ele_t *head; /* Linked list of elements */ /* You will need to add more fields to this structure to efficiently implement q_size and q_insert_tail */ list_ele_t *tail; int size; } queue_t;
  • q_insert_tail:

queue.c

問題與討論

​​​​free()
tags: 作業,Queue
Select a repo