Передача в функцию - C (СИ)
Формулировка задачи:
Правильно ли я передаю arg в функцию listInsert? Нет возможности проверить. Ниже структура и фунция встаки аргумента.
Функции
Структура
double complex arg;
scanf("%d", &re);
scanf("%d", &im);
arg=re+im*I;
listInsert(&list, pos - 1, arg);void listInsert(List *list, const int index, const LIST_TYPE value)
{
int prev, nextHole;
if (list->_size == list->_capacity)
{
printf("Ошибка. Список полон\n");
return;
}
if (list->_size)
{
if (index < 0 || index > list->_size)
{
printf("Ошибка. Позиция не найдена\n");
return;
}
}
else if (index != 0)
{
printf("Ошибка. Позиция не найдена\n");
return;
}
nextHole = list->_arr[list->_hole]._next;
if (index == 0)
{
list->_arr[list->_hole]._next = list->_first;
list->_first = list->_hole;
}
else
{
prev = findPrev(list, index);
list->_arr[list->_hole]._next = list->_arr[prev]._next;
list->_arr[prev]._next = list->_hole;
}
list->_arr[list->_hole]._data = value;
list->_hole = nextHole;
list->_size++;
printf("Элемент %g%+gi вставлен в список\n", creal(arg), cimag(arg));
int findPrev(List *list, const int index)
{
int i, prev = list->_first;
if (index == 0)
return END;
for (i = 0; i < index - 1; i++)
prev = list->_arr[prev]._next;
return prev;
}
}typedef double complex LIST_TYPE;
typedef struct _Item
{
LIST_TYPE _data;
int _next;
int _prev;
} Item;
typedef struct _List
{
Item *_arr;
int _first;
int _hole;
int _capacity;
int _size;
} List;Решение задачи: «Передача в функцию»
textual
Листинг программы
scanf("%d", &re);