[1002] Exam note data structure simplified code and Xiaoxiaoshui

Source: Internet
Author: User


----012345---

----0123345---

/********

Code

if (i<1| | i>l->last+2) printf ("I's position is out of bounds \ n"); return;

if (l->last>=maxsize-1) printf ("The list is full \ n"); return;

for (k=l->last;k>i-1;k--) l->elem[k+1]=l->elem[k];

Elem[i-1]=e; l->last++;

return OK;

********/

[h| NULL] [Data|next]

[H|&P1] [P1|&P2] [p2| NULL]

The first node of the head junction.

Head pointer p1=h->next;

*h= (linklist) malloc (sizeof (Node));

(*l)->next=null;

Head Insertion method

[H|&P1] [P1|&P2] [p2| NULL]

S= (node*) malloc (sizeof (Node)); [s| NULL]

s->data=p; [p| NULL]

s->next=h->next; [P|&P1]

h->next=p; [H|&p] [P|&P1] [P1|&P2] [p2| NULL]

Tail interpolation method

[H|&p] [p| NULL]

S= (node*) malloc (sizeof (Node)); [s| NULL]

s->data=c; [c| NULL]

p->next=s; [H|&p] [P|&c] [c| NULL]

P=s; P↑p↑s


Stack

typedef struct{se ELEM[5];INT top;} SK;

"[0][1][2][3][4]"

↑↑

Top

Into the Stack ""

S->top=size-1 stack full eg:5-1=4;

Because top is initialized to-1, the stack is s->top++; first.

s->elem[s->top]=x; dual directivity; eg:top=2; "[0][1][x][3][4]"

Out of the stack "

*x=s->elem[s->top]; can only be performed by a top-out (expression to implement the function of the stack)

The *x pointer points to the position of the original top, and X takes out its value (the actual x is still at x at the machine)

top--, maintenance stack, can reflect the meaning of the stack;

Queue

typedef struct node{QE data;struct Node *next;} Lqnode;

typedef struct{lqnode *front; Lqnode *rear; }LQ;

【[][][][]】? "[f|*][r|*]"

Q->front= (Lqnode *) malloc (sizeof (Lqnode)); [e|*]

if (q->front!=null)

{

q->rear=q->front; [f|*] [R |*]

q->front->next=null; [f| NULL]

return (T);

}

Insert ""

n= (Lqnode *) malloc (sizeof (Lqnode)); [e|*]

if (n!=null)

{

n->data=x; [X| *]

n->next=null; [x| NULL]

q->rear->next=n; [f| null][r | &x] [x| NULL]

q->rear=n; R↑r↑n

return (T);

}

The tail is inserted, the team head out of the team; (Can you re-define yourself?) )

Out of the team "[f| null][r | &x] [x| NULL]

p=q->front->next; P↑↑p->next

q->front->next=p->next; [f| NULL] [x| NULL]

*p= P->data

Free (p); Frree ([r | &x])

String string

The whole string of strings; strings

Sequential tables for storage

typedef struct{CHAR E[max];int len;}ss;

String insertion in a lot of cases "----------"

【------[*****]-----】

↑↑↑↑

Throw it away.

String delete move forward len--;

for (i=p+l;i<s->len;i++) s->ch[i-l]=s.ch[i];s->len=s->len-l;

The string of empty (s.len==0)? (return 1):(return 0);/* limited to pseudo-code notes */

String copy for (i=0;i<len;i++) s.ch[i]=t.ch[i];s->len=t->len;

string comparison for (i=0;i<len;i++) if (S.ch[i]!=t.ch[i]) return (S.ch[i]-t.ch[i]);

String length return S.len

String Empty s->len=0;


[1002] Exam note data structure simplified code and Xiaoxiaoshui

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.