# include
# include
//the definition of a singly linked list
Typedef struct node {
The int data;
Struct node * next;
} node, * linklist;
Void createfromtail linklist (l)
{
The node * s * r;
char c;
Int flag=1;
R=l;
While (flag)
{
C=getchar ();
If (c!='2')
{
S=(*) malloc (sizeof (node));
S - & gt; data=https://bbs.csdn.net/topics/c;
R - & gt; Next=s;
R=s;
}
The else
{flag=0;
R - & gt; Next=NULL;
}
}
}
Void Binadd linklist (l)
//to take the lead node singly linked lists to store a binary number l, add 1 operation
{
Q, the node * * r * s;
Q=l - & gt; Next;
R=l;
While (q!=NULL)
//to find the last node of a range of 0
{
If (q - & gt; data=https://bbs.csdn.net/topics/=0)
R=q;
Q=q - & gt; Next;
}
If (r!=l)
R - & gt; Data=https://bbs.csdn.net/topics/1;/* will be the final value of the node of a range of 0 assigned to 1 */
//was not found the range of 0 node
The else
{
S=(*) malloc (sizeof (node));/* to apply for a new node storing the highest carry */
S - & gt; Data=https://bbs.csdn.net/topics/1;/* domain assigned to 1 */
S - & gt; Next=l - & gt; Next;
L - & gt; Next=s;/* */
after insert an end nodeR=s;
}
R=r - & gt; Next;
While (r!=NULL)//to the back of the assignment of the value of the city for all nodes 0
{
R - & gt; data=https://bbs.csdn.net/topics/0;
R=r - & gt; Next;
}
}
Void PrintList (linklist l)
{//output
Linklist p=l - & gt; Next;
While (p!=NULL)
{
Printf (" % d ", p - & gt; The data);
P=p - & gt; Next;
}
}
Void main ()
{
Linklist l;
L=(*) malloc (sizeof (node));
Createfromtail (l);
PrintList (l);
Binadd (l);
PrintList (l);
}
Where is wrong
CodePudding user response:
C=getchar ();If (c!='2')
{
S=(*) malloc (sizeof (node));
S - & gt; data=https://bbs.csdn.net/topics/c- '0'.//here change
R - & gt; Next=s;
R=s;
}