написал прогу по двусвязным спискам ,и было задание - вывести все элементы в обратном порядке, использовав рекурсию... в обычных списках сделал, а тут переделал, но Warning(Warning: suspicious pointer conversion in function recurs_node) один показывает и не работает функция... !!!-знаками пометил, где ругается компилятор
Код:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct node
{
int data;
char a;
struct node *next;
struct node *previos;
}ITEM;
typedef struct head
{
struct node *first;
struct node *last;
}HEAD;
HEAD* add_node(HEAD* head, int new_data, char new_a)
{
ITEM *new_item, *prev;
new_item=(ITEM *)malloc(sizeof(ITEM));
if(new_item==NULL)
{
printf("Oshibka videlenija pamjati\n");
return head;
}
new_item->data=new_data;
new_item->a=new_a;
if(head==NULL)
{
head=(HEAD *)malloc(sizeof(HEAD));
puts("Spisok sozdan!");
new_item->next=NULL;
new_item->previos=NULL;
head->first=head->last=new_item;
return head;
}
if(head->first->data<new_data)
{
printf("Element %d vstavlen v nachalo spiska\n",new_data);
new_item->next=head->first;
head->first->previos=new_item;
head->first=new_item;
new_item->previos=NULL;
return head;
}
prev=head->first;
while(prev->next->data<new_data)
{
if(prev->next->data<new_data)
{
printf("Element %d vstavlen v seredinu spiska\n",new_data);
new_item->next=prev->next;
prev->next=new_item;
new_item->previos=prev;
new_item->next->previos=new_item;
return head;
}
else
{
prev=prev->next;
}
}
printf("Element %d vstavlen v konec spiska\n",new_data);
head->last->next=new_item;
new_item->previos=head->last;
head->last=new_item;
new_item->next=NULL;
return head;
}
HEAD* delete_node(HEAD* head, int kluch)
{
ITEM *cur, *prev;
prev=NULL;
cur=head->first;
while(cur!=NULL && cur->data>=kluch)
{
if(cur->data==kluch)
{
while(cur->data==kluch)
{
printf("Udalenie elementa %d\n",cur->data);
if(prev==NULL)
{
head->first=cur->next;
if(head->first!=NULL)
head->first->previos=NULL;
if(head->first==NULL)
head->last=NULL;
}
else if(cur==head->last)
{
head->last=prev;
prev->next=NULL;
}
else
{
prev->next=cur->next;
cur->next->previos=prev;
}
free(cur);
cur=cur->next;
}
}
prev=cur;
cur=cur->next;
}
printf("Element %d otsutstvuet v spiske\n",kluch);
return head;
}
void vivod_nachalo(HEAD* head)
{
ITEM *cur;
if(head==NULL || head->last==NULL)
{
puts("Spisok pust!");
return;
}
cur=head->first;
while(cur!=NULL)
{
printf("%d ", cur->data);
printf("%c ", cur->a);
cur=cur->next;
}
puts("");
}
void vivod_konec(HEAD* head)
{
ITEM* cur;
if(head==NULL || head->last==NULL)
{
puts("Spisok pust!");
return;
}
cur=head->last;
while(cur!=NULL)
{
printf("%d ",cur->data);
printf("%c ",cur->a);
cur=cur->previos;
}
puts("");
}
int find_node(HEAD* head, int find_data)
{
ITEM *cur;
cur=head->first;
while(cur!=NULL && cur->data>=find_data)
{
if(cur->data==find_data)
{
printf("Element %d naiden\n",find_data);
return 1;
}
cur=cur->next;
}
printf("Element %d NE naiden\n",find_data);
return 0;
}
void recurs_node(HEAD* head)
{ ITEM *cur=head->first;
if (cur->next!=NULL)
!!!!!!! recurs_node(cur->next); !!!!!!!!
printf("%5d%3c\n",cur->data,cur->a);
}
int main()
{
HEAD *Head=NULL;
char key;
int chislo, kluch;
char chislo1;
while(1)
{
clrscr();
puts("1 - Dobavit' element");
puts("2 - Udalit' element");
puts("3 - Vivod spiska");
puts("4 - Naiti element");
puts("5 - Spec. funkciya");
puts("ESC - Exit");
key=getch();
switch(key)
{
case '1':
puts("Enter number <int>");
fflush(stdin);
scanf("%d",&chislo);
puts("Enter number <simvol>");
fflush(stdin);
scanf("%c",&chislo1);
Head=add_node(Head,chislo,chislo1);
getch();
break;
case '2':
puts("Enter number");
scanf("%d",&chislo);
Head=delete_node(Head,chislo);
getch();
break;
case '3':
vivod_nachalo(Head);
vivod_konec(Head);
getch();
break;
case '4':
puts("Vvedite chislo");
scanf("%d",&chislo);
find_node(Head,chislo);
getch();
break;
case '5':
clrscr();
if (Head==NULL)
printf("Spisok ne sozdan\n");
else
{
printf("Spisok w obratnom porjadke\n");
recurs_node(Head);
}
break;
case 27:
puts("Exit");
return 0;
}
}
}