Implementation of sequential chain list and implementation of linked list query

Source: Internet
Author: User

The program realizes the creation of the linked list, the query function of the linked list

The Create () method implements the creation of sequential lists and calls the Find () method of the linked list query module

The Find () method implements a sequential list of queries

#include <stdio.h>

#define MAXSIZE 100//defines the length of an array

Defines a contiguous array sqlist

typedef struct sqlist{

int date [maxsize];

int length;

}sqlist;


See if there is a number x in the array

If there is, returns the position of the array, if not, returns 0;

int find (sqlist l,int x) {

Int J;

int k = 0;

for (j= 1; j<=l.length; ++j) {

if (X==l.date[j]) {

K= J;

}

Else

k=0;

}

return k;

}




Create an ordered list of links

An array corresponds to a pointer, and the pointer is stored in this method and cannot be

Continue to use

void Create (SqList l) {

int ll; The length of the sequential list

printf ("Length of the input list: \ n");

scanf ("%d", &ll);

L.length = ll;

Set up a sequential chain list

for (int i =1;i<= l.length; i++) {

printf ("Please enter%d numbers:", i);

scanf ("%d", &l.date[i]);

}

Find the sequential list to find out if there is a value x

In the list of sequential lists

int x;

printf ("Please enter a number x:");

scanf ("%d", &x);

Call lookup method Find ()

int k = Find (l, x);

if (k==0) {

printf ("Without this number");

}

Else

printf ("This number is in the position of the array%d\n", K);

}

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

{

Defining a sequential array

SqList l;

Calling functions

Create (L);


printf ("Hello, world!\n");

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.