Basic operation of sequential table and linked list

Source: Internet
Author: User

SqList

typedef struct
{
Elemtype *elem; Storage space Base
int length; Current length
int listsize; Current capacity
}sqlist;

L->elem = (elemtype*) mallloc (list_init_size*sizeof (elemtype)); l->length = 0; L->listsize = list_init_size;

L->elem = (elemtype*) realloc (L->elem, (l.listsize+listincrement) *sizeof (elemtype));

if (NULL = = L->elem) exit (OVERFLOW);

Destroy Operation Free (l->elem); l->elem = NULL; l->length = l->listsize = 0;

Sequential tables, sequential storage, initialization operations assign a predefined size array space to the order table, and redistribution (realloc) due to insufficient space to insert the element;

Linklistt

typedef struct LNODE

{
Elemtype data;
struct Lnode *next;
}lnode,*linklist;

L = (linklist) malloc (sizeof (Lnode)); L->next = NULL;
Destroy Destroy P = L; L = L->next;free (p); Clear clear only to retain the head node;

Linked list, create nodes and release nodes, nodes with data and pointers two information;

Comprehensive: Consider whether insert, delete operation is reasonable, otherwise exit (ERROR); Consider whether the storage allocation is successful (sqlist), otherwise exit (OVERFLOW);

Basic operation of sequential table and linked list

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.