Example #1
0
//// concatenate 2 lists, which are formed with (cons * (cons * ... nil))
pntr connect_lists(task *tsk, pntr *list1, pntr *list2)
{
	cell *lastCell = get_last_cell(tsk, list1);
	
	make_pntr(lastCell->field2, get_pntr(*list2));
	return *list1;
}
Example #2
0
/** @brief Inserts a value at the endo of a List
 *
 *  @param list the List into which the value will be appended
 *  @param value the value to be appended
 *  @return the pointer to the newly created cell
 */
Cell *append(List *list, int value){
 	Cell *addr = (Cell*)malloc(sizeof(Cell));
 	addr->content = value;
 	addr->next = (Cell*)0;
 	Cell *ptr = get_last_cell(list);
 	if(ptr) return ptr->next = addr; //Not empty list
 	return list->first = addr; 	//empty list
}
Example #3
0
/** @brief Inserts a value at the end of a List
 *
 *  @param list the List into which the value will be appended
 *  @param value the value to be appended
 *  @return the pointer to the newly created cell
 */
Cell *append(List *list, int value){
	if(VERBOSE_LVL >= LOW_VERBOSE){
		printf("append(%p, %d)\n", (void*)list, value);
	}
 	Cell *addr = (Cell*)malloc(sizeof(Cell));
 	addr->content = value;
 	addr->next = (Cell*)0;
 	Cell *ptr = get_last_cell(list);
 	if(ptr) return ptr->next = addr; //Not empty list
 	return list->first = addr; 	//empty list
}
Example #4
0
/** @brief Inserts a cell at the end of a List
 *
 *  @param list the List into which the Cell will be appended
 *  @param cell the cell to be inserted
 *  @return the pointer to the newly created cell
 */
Cell *append_cell(List *list, Cell *cell){
	if(VERBOSE_LVL >= LOW_VERBOSE){
		printf("append_cell(%p, %p)\n", (void*)list, (void*)cell);
	}
	if(list_len(list) == 0){
		list->first = cell;
	} else {
		get_last_cell(list)->next = cell;
	}
	cell->next = 0;
	return cell;
}
Example #5
0
/** @brief Merges two lists together
 *
 *  @param list1 the List to which the second list will be merged
 *  @param list2 the List that will be merged to the first one and will be emptied
 */
List *merge_lists(List *list1, List *list2){
	if(VERBOSE_LVL >= LOW_VERBOSE){
		printf("merge_lists(%p, %p)\n", (void*)list1, (void*)list2);
	}
	if(is_empty(list1)){
		list1->first = list2->first;
	} else {
		get_last_cell(list1)->next = list2->first;
	}
	list2->first = 0;
	return list1;
}
Example #6
0
/** @brief Reverses the order of the list
 *
 *  @param list the List to be reversed
 */
void reverse_list(List *list){
	recursive_reverse_list(list, list->first, get_last_cell(list));
}
Example #7
0
/** @brief Reverses the order of the list
 *
 *  @param list the List to be reversed
 */
void reverse_list(List *list){
	if(VERBOSE_LVL >= LOW_VERBOSE){
		printf("reverse_list(%p)\n", (void*)list);
	}
	recursive_reverse_list(list, list->first, get_last_cell(list));
}