/*
This program mainly realizes the storage and output of the data chain, and writes the output value in a file.
"The main code of this program is in the definition:
Lnode *p=l->next;//defines a node pointer p points to the next node of the head node
”
And after the data chain is established, the pointers on the data chain cannot be returned, only the method of modifying the data chain (the method of the methods in the way) is invoked using the method of the creation.
*/
#include <stdio.h>
#include <stdlib.h>
11th Data Link
typedef struct lnode{
int date;
struct Lnode *next;
}lnode;
Outputs a value in a data chain and saves the output values to a file
void Displist (Lnode *l)
{
FILE *f;
f = fopen ("/users/tarena0/desktop/lnode.txt", "w");
Lnode *p=l->next;//defines a node pointer p points to the next node of the head node
while (p) {//if p is not empty then loop
printf ("%d\n", p->date);
fprintf (F, "%d", p->date);
p=p->next;//moving pointer p traversing linked list
}
Fclose (f);
}
Set up a data chain to store the array in the data chain
void Create (Lnode *l, int m[], int n) {
Define two pointers, one to hold the head pointer and the other to create a data link
Lnode *s, *r;
Request a node for a data link
L = (lnode*) malloc (sizeof (Lnode));
R = l;//used to hold the head pointer
L->next = null;//head node empty
for (int i= 1; i<= N; i++) {
s = (Lnode *) malloc (sizeof (Lnode));
Define a Dynamic Data link node that is used to request space and establish a data chain
printf ("Please enter%d numbers:", i);
scanf ("%d", &m[i]);
Data link establishment of tail interpolation method
S->date = M[i];
R->next = s;
r = r->next;
}
R->next = NULL;
Displist (l);
}
int main (int argc, const char * argv[])
{
int n;
int m[n];
Lnode *l;
printf ("Please enter array length n:");
scanf ("%d", &n);
Create (L, m, n);//Method call
return 0;
}