コード例 #1
0
ファイル: queue.c プロジェクト: ivanicspeter92/2016-aalto-c
int Queue_drop(Queue *q, const char *id) {
    if (q->first != NULL) {
        if (strcmp(q->first->id, id) == 0) {
            Queue_dequeue(q);
            return 1;
        } else {
            struct student* next_student = q->first;
            struct student* last_student;
            do {
                if (strcmp(next_student->id, id) == 0) {
                    struct student* student_to_delete = next_student;
                   
                        last_student->next = student_to_delete->next;
                    
                    if (student_to_delete == q->last) {
                        q->last = last_student;
                        last_student->next = NULL;
                    }
                    free_student(student_to_delete);
                    return 1;
                }
                
                last_student = next_student;
                next_student = next_student->next;
            } while(next_student != NULL);
        }
    }
    
    return 0;
}
コード例 #2
0
ファイル: queue.c プロジェクト: ivanicspeter92/2016-aalto-c
/// Removes the first member of the queue, and releases all memory allocated for it.
/// \param q
/// \return 1, if something was removed; or 0 if nothing was removed, i.e., because the queue was already empty.
int Queue_dequeue(Queue *q) {
    if (q->first != NULL) {
        if (q->first == q->last) { // only one item in the queue
            free_student(q->first);
            q->first = NULL;
            q->last = NULL;
        } else { // more than one item
            struct student* first_item = q->first;
            q->first = first_item->next;
            free_student(first_item);
        }
        
        return 1;
    }
    
    return 0;
}
コード例 #3
0
ファイル: test.c プロジェクト: ravishchawla/DataStructures
void free_student_nulls(void *data)
{

	if(data == NULL)
		return;
	free_student(data);

	


}