Home > Back-end >  Excuse me where is this right?
Excuse me where is this right?

Time:09-27

#include
#include

# define TRUE 1
# define FALSE 0
# define OK 1
# define the ERROR - 1
# define OVERFLOW - 2

typedef int Status;
Typedef int ElemType;

Typedef struct LNode
{
ElemType data;
Struct LNode * next;
} LNode * LinkList;

The Status InitList (LinkList & amp; L)
{
//set up an empty list, L for head node pointer.
L=(LinkList) malloc (sizeof (LNode));//generated head node
if(! L)
Return the ERROR;

L - & gt; Next=NULL;
return OK;
}//InitList
Void CircleList (LinkList & amp; L)//linear list into a circular linked list
{
LinkList p;
int i;
P=L;
for(i=0; p-> next; I++)
P=p - & gt; next;
p-> Next=L;
}
Status GetElem (LinkList L, int I ElemType & amp; E)
{
//L to take the lead node cycle singly linked lists head pointer.
//when the ith element exists, its value is assigned to e and return OK, otherwise returns the ERROR
LinkList p;
int j;
P=L - & gt; next;
J=1;//initialization, pointing to the first node p, j for the counter
While (p& & J{
//pointer to find back, until p points to the ith element
P=p - & gt; Next;
++j;
}
if (! P | | j> I)
Return the ERROR;//the element does not exist I
E=p - & gt; The data;//get the ith element
return OK;
}//GetElem

The Status ListInsert (LinkList & amp; L, int I ElemType e)
{
//in the lead node of the circular linked list in the case of a position before I insert element e L
LinkList p, s;
int j;
P=L;
j=0;
While (p& & J{
P=p - & gt; next;//to find the first I - 1 node
++j;
}
If (! P | | j> I - 1)
Return the ERROR;//I less than 1 or greater than the table long
S=(LinkList) malloc (sizeof (LNode));//generated new node
if(! S)
Return the ERROR;
s-> Data=https://bbs.csdn.net/topics/e;
s-> Next=p - & gt; next;//insert L
p-> Next=s;
return OK;
}
The Status of Sort (LinkList L, LinkList & amp; L1, LinkList & amp; L2, LinkList & amp; L3)
{
LinkList p, q;
P=L - & gt; next;
Int I=1, j=1, k=1;
While (p)
{
If (p - & gt; Data>='0' & amp; & p-> Data<='9')
{
//q=p;
ListInsert (L1, i++, p - & gt; The data);

//free (q);
}
Else if ((p - & gt; Data>='a' & amp; & p-> Data<='z') | | (p - & gt; Data<='A' & amp; & p-> Data<='Z'))
{
//q=p;
ListInsert (L2, j++, p - & gt; The data);

//free (q);
}
The else
{
//q=p;
ListInsert (L3, k++, p - & gt; The data);

//free (q);
}
P=p - & gt; next;

}
return OK;

}
The Status ListLength LinkList (L)
{
//the lead node
LinkList p;
Int len=0;
P=L - & gt; next;
While (p)
{
len++;
P=p - & gt; next;
}
Return len.
}
Void ListPrint LinkList (L)//will list La data elements from the header to the footer in turn according to
{
LinkList p;
int i;
P=L - & gt; next;
if(! P)
Printf (" output list failed! \n");
for(i=0; p; I++)
{
Printf (" % c ", p - & gt; The data);
P=p - & gt; next;
}
printf("\n");
}
Int main ()
{
LinkList L, L1, L2, L3;
InitList (L);
InitList (L1);//for digital
InitList (L2);//for characters
InitList (L3);//for other characters
LinkList p, q;
P=L - & gt; next;



ElemType e;
int i;

//enter a two-way linked list
for(i=1; i<=5; I++)
{
The scanf (" % c ", & amp; e);

ListInsert (L, I, e);


}
Sort (L, L1, L2, L3);
Int len1, len2 len3;
Len1=ListLength (L1);
Len2=ListLength (L2);
Len3=ListLength (L3);
Printf (" output number: \ n ");
ListPrint (L1);
Printf (" output letter: \ n ");
ListPrint (L2);

Printf (" output other characters: \ n ");
ListPrint (L3);
CircleList (L1);
CircleList (L2);
CircleList (L3);
return 0;




}

CodePudding user response:

When I enter 12345, it is only in the letters where output 123
  • Related