Home > Back-end >  Data structure is a yuan quadratic derivative
Data structure is a yuan quadratic derivative

Time:10-02

#include
#include
Typedef struct LNode
{int en;
Int cn;
struct LNode *next;
} LinkNode;
Void InitList (LinkNode * & amp; L)
{
L=(LinkNode *) malloc (sizeof (LinkNode));
L - & gt; Next=NULL;
}
Void DestoryList (LinkNode * & amp; L)
{
Pre=L LinkNode * and * p=L - & gt; Next;
While (p!=NULL)
{free (pre);
The pre=p;
P=pre - & gt; Next;
}
Free (pre);
}
Void print (LinkNode * & amp; L) {
LinkNode * p=L - & gt; Next;
while (p!=NULL) {
If (p - & gt; cn!=0)
Printf (" % d ", p - & gt; Cn);
P=p - & gt; Next;
}
printf("\n");
}
Void equation (LinkNode * & amp; L) {
LinkNode * p=L;
While (p - & gt; Next!=NULL) {
P=p - & gt; Next;
If (p - & gt; En==0) {
P - & gt; Cn=0;
}
The else {
P - & gt; Cn *=p - & gt; En.
P - & gt; En -;
}
}
}
Int main ()
{
LinkNode * L, * p=L;
Int cn and en.
Char s;
InitList (L);
While (the scanf (" % d % d ", & amp; Cn, & amp; En)! EOF)={
LinkNode * node=(LinkNode *) malloc (sizeof (LinkNode));
Node - & gt; Cn=cn;
Node - & gt; En=en;
Node - & gt; Next=NULL;
P - & gt; Next=node;
P=node;
}
Equation (L);
Print (L);
DestoryList (L);
return 0;
}

CodePudding user response:

 # include 
#include

Typedef struct LNode
{
Int en;
Int cn;
struct LNode *next;
} LinkNode;

Void InitList (LinkNode * & amp; L)
{
L=(LinkNode *) malloc (sizeof (LinkNode));
L - & gt; Next=NULL;
}
Void DestoryList (LinkNode * & amp; L)
{
Pre=L LinkNode * and * p=L - & gt; Next;
While (p!=NULL)
{free (pre);
The pre=p;
P=pre - & gt; Next;
}
Free (pre);
}
Void print (LinkNode * & amp; L) {
LinkNode * p=L - & gt; Next;
while (p!=NULL) {
If (p - & gt; cn!=0)
Printf (" % d ", p - & gt; Cn);
P=p - & gt; Next;
}
printf("\n");
}
Void equation (LinkNode * & amp; L) {
LinkNode * p=L;
While (p - & gt; Next!=NULL) {
P=p - & gt; Next;
If (p - & gt; En==0) {
P - & gt; Cn=0;
}
The else {
P - & gt; Cn *=p - & gt; En.
P - & gt; En -;
}
}
}
Int main ()
{
LinkNode * L, * p;//=L;
Int cn and en.
Char s;
InitList (L);

P=L;
While (the scanf (" % d % d ", & amp; Cn, & amp; En)! EOF)={
LinkNode * node=(LinkNode *) malloc (sizeof (LinkNode));
Node - & gt; Cn=cn;
Node - & gt; En=en;
Node - & gt; Next=NULL;
P - & gt; Next=node;
P=node;
}
Equation (L);
Print (L);
DestoryList (L);
return 0;
}

For your reference ~

Attention to p L need to initialize the head node, otherwise the point p and L uninitialized wild pointer,

CodePudding user response:

#include
#include
Typedef struct LNode
{
Int en;
Int cn;
struct LNode *next;
} LinkNode;
Void InitList (LinkNode * * L)
{
* L=(LinkNode *) malloc (sizeof (LinkNode));
(* L) - & gt; Next=NULL;
}
Void DestoryList (LinkNode * * L)
{
Pre=LinkNode * * L, * p=(* L) - & gt; Next;
While (p!=NULL)
{
Free (pre);
The pre=p;
P=pre - & gt; Next;
}
Free (pre);
}
Void print (LinkNode * L) {
LinkNode * p=L - & gt; Next;
If (L - & gt; Next==NULL)
Printf (" 0 0 ");
The else {
While (p!=NULL) {
If (p - & gt; En==1)
P=p - & gt; Next;
The else {
Printf (" % d % d ", p - & gt; Cn, p - & gt; En);
P=p - & gt; Next; }
}
}
}
Void equation (LinkNode * * L) {
LinkNode * p=(* L) - & gt; Next, * q;
While (p!=NULL) {
Q=p - & gt; Next;
If (p - & gt; Cn==0) {
P - & gt; Next=q - & gt; Next;
Free (q);
}
The else {
P - & gt; Cn *=p - & gt; En.
P - & gt; En -;
}
P=p - & gt; Next;
}
}
Int main ()
{
LinkNode * L=NULL, * p;
Int cn and en.
InitList (& amp; L);
P=L;
While (1) {
The scanf (" % d % d ", & amp; Cn, & amp; En);
LinkNode * node=(LinkNode *) malloc (sizeof (LinkNode));
Node - & gt; Cn=cn;
Node - & gt; En=en;
P - & gt; Next=node;
P=node;
If (getchar ()=='\ n') break;
}
P - & gt; Next=NULL;
Equation (& amp; L);
Print (L);
DestoryList (& amp; L);
return 0;
}

CodePudding user response:

#include
#include
Typedef struct LNode
{
Int en;
Int cn;
struct LNode *next;
} LinkNode;
Void InitList (LinkNode * * L)
{
* L=(LinkNode *) malloc (sizeof (LinkNode));
(* L) - & gt; Next=NULL;
}
Void DestoryList (LinkNode * * L)
{
Pre=LinkNode * * L, * p=(* L) - & gt; Next;
While (p!=NULL)
{
Free (pre);
The pre=p;
P=pre - & gt; Next;
}
Free (pre);
* L=NULL;//remember set to NULL after release
}
Void print (LinkNode * L) {
LinkNode * p=L - & gt; Next;
If (L - & gt; Next==NULL)
Printf (" 0 0 ");
The else {
While (p!=NULL) {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related