34 67 89 2223 44 55 775 332 345 675 4234 123 565 345 98 1213 9876 90 353 4242
left ring
4242 353 90 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34
353 90 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242
90 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353
9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353 90
incre test
input value 888
888 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353 90
input value 777
777 888 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353 90
input value 666
666 777 888 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353 90
left ring
666 777 888 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353 90
777 888 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353 90 666
888 9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353 90 666 777
9876 1213 98 345 565 123 4234 675 345 332 775 55 44 2223 89 67 34 4242 353 90 666 777 888
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#include <stdio.h>
#include <stdlib.h>
typedef struct _binary_list
{
struct _binary_list *left;
struct _binary_list *right;
ushort data;
}binary_list;
binary_list *head=NULL;
void insert (int data)
{
binary_list *tmp=NULL;
if(!head)
{
head=(binary_list*)calloc ( 1,sizeof (binary_list ));
head->data=data;
head->left=head;
head->right=head;
}
else
{
tmp=(binary_list*)calloc ( 1,sizeof (binary_list ));
tmp->data=data;
tmp->left=head;
tmp->right=head->right;
head->right->left=tmp;
head->right=tmp;
head=head->right;
}
}
int gethead ()
{
return head->data;
}
void left_ring()
{
head=head->left;
}
void right_ring()
{
head=head->right;
}
left_dump()
{
binary_list *label=head;
do
{
printf("%d ",gethead() );
head=head->left;
}
while ( label!=head);
}
right_dump()
{
binary_list *label=head;
do
{
printf("%d ",gethead());
head=head->right;
}
while(label!=head);
}
int main()
{
ushort data[]={34,67,89,2223,44,55,775,332,345,675,4234,123,565,345,98,1213,9876,90,353,4242};
uint i,j,value;
for( i=0;i<sizeof(data)/sizeof(ushort);i++)
{
insert ( data[i]);
printf("%d ",data[i]);
}
printf("\nleft ring\n");
left_dump();
left_ring ();
printf("\n");
left_dump();
left_ring();
printf("\n");
left_dump();
left_ring();
printf("\n");
left_dump();
/*
printf("\nright ring\n");
right_dump();
right_ring();
printf("\n");
right_dump();
right_ring();
printf("\n");
right_dump();
right_ring();
printf("\n");
right_dump();
*/
printf("\nincre test\n");
value=888;
printf("\ninput value %d \n",value);
insert( value);
left_dump();
value=777;
printf("\ninput value %d \n",value);
insert( value);
left_dump();
value=666;
printf("\ninput value %d \n",value);
insert( value);
left_dump();
printf("\nleft ring\n");
left_dump();
left_ring ();
printf("\n");
left_dump();
left_ring();
printf("\n");
left_dump();
left_ring();
printf("\n");
left_dump();
}