List construction and the output of the linked list

Source: Internet
Author: User

Problems with pointers to resolving data stored on linked lists that cannot be exported

The construction of linked lists, and the implementation of linked list access

Use of pointers

Pointers, linked lists, storage of linked lists, access to linked lists

#include <stdio.h>

#include <stdlib.h>//import a C library file to dynamically assign addresses, NULL empty addresses for the bottom malloc

#define MAX 10//11th Max value


typedef struct lnode{//define linked list, linked list structure

int date;

struct Lnode *next;

}lnode;


Storing data in an array on a linked list, storing the list (calling function)

int *create (Lnode *l,int m[],int N) {

Lnode *r,*s; First two linked list pointers

L = (Lnode *) malloc (sizeof (Lnode)); Dynamically assigns a linked list node L, the head pointer.

R = l; Give your head pointer to R and keep your head pointer.

L->next = NULL; Initialization definition of the head pointer

for (int i = 1; i<=n; i++) {//Data link Table storage

s = (lnode*) malloc (sizeof (Lnode));

printf ("Please enter%d numbers in array m: \ n", i);

scanf ("%d", &m[i]);

S->date = M[i]; Using the tail interpolation method to set up the array chain list

R->next = s;

r = r->next;

}

R->next= NULL;

return l; Returns the head pointer of the linked list

}


Data on the output list (call function)

void Prin (Lnode *l) {

L = l->next;

for (int j= 1; j<=10; J + +) {

printf ("%d\n", l->date);

L = l->next;

}

}



Main function

int main (int argc, const char * argv[])

{

Lnode *l;

int M[max];

int n = 10;

Lnode *p =create (L, M, N); Call Linked list build function

Prin (P); Call the linked list output Cheng

Insert code here ...

return 0;

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.