Generalized tables and previous pseudo-code

Source: Internet
Author: User

struct {*elem, length,size}
L init: Apply for Elem space, if successful, Length=0;size =100
Ignore: (SqList L), use the declared list to initialize
int Insert:elem is the first address, determines whether Elem is empty, returns empty, otherwise gets elem[length],if (length+1>100) {expands space}length++,elem[length]= Data,return L
Ignore: L, insert (L,index,data) 1, determine if index is out of bounds if (i<1 | | I>l.length) return error;
2, the current list is full (l.length >= l.size) {Expand the space, if the expansion succeeds, new address = new space, give maximum length plus extended length, otherwise exit}
3,p is the current element, move the position of P backward, insert, length +1
void Insertaftertail:(List,data) inserts an element at the end of the linear table, determines whether the subscript is to the maximum value, and if so, increments the table space by the Insert method, otherwise length++, the last size is the data
int Delete: (l,i,data), determine if I is out of bounds (i<1| | I>l.length) return error, determine whether the table is empty, (l.length==0) return error, if all is satisfied, the data after P = Elem[i],i moves forward one, free (p) reutrnl
Ignore:--length
int locate: (l.value): 1, determine if the first address of L is present, if there is no return error, if there is a elem[i] start traversal, if you do not encounter the pointer has been moved backwards, if you encounter an exit loop, print out I
Ignore: Don't judge whether the first address exists
Sequential table merging: Two sequential tables in ascending order, merged into one, i=j=0 (i<la.length && j<lb.length) in the case that both tables have values, {take the A.B element compared with the lowest value, put the subscript +1}, If the two elements are not the same, there is only one last
if (i>=la.length) {only for B operation} Likewise B is also the last to return C
Ignore: The length of the first C =a+b length of the sum, after the application of C space, the final judgment of the table has not reached the maximum, do not judge the other table, because from the while execution down there must be only one table


LinkedList
struct Lnode {datatype data,struct *next}lnode,*linklist
L Getelem: (l,value) to see if the first address exists, if there is no Exit (0), if there is a traversal, know that next is empty. Returns 1 if the middle encounters an element that satisfies, otherwise returns 0
Ignore: (L,i,e) When the first element is present, assign the value to E and return, and the above meaning is completely misunderstood.
1, traversing the count until I, if I,p does not satisfy the exit, otherwise returns the element I
L crteateinit: (&l) Add the head knot, next point is empty, do not need to apply for the table space, and then there is no
Ignore: (l,n) Insert value of n elements, loop technology and request space, enter values,
int Listinsert:(L,i,data) If the lead node is first init, then look at I is the length of <0 or >list, if satisfied if I is the last, next=elem[i], if I am inserted between the head node and the tail node, Without moving the elements,
Ignore: Generate new node, not lead node
int listdelete: (l,i,e) Look for the node, if the position is not reasonable exit, if the reasonable deletion,,, with no distinction I just is the last node
Put two ordered linked lists into an unordered list: Take the head node separately, compare the size, insert it, until the end, take the same comparison method as the sequential table,
Ignore: Only at last do not compare each other, the first address to C on the line
Insert from Tail: Determines whether the linked list is empty, if not empty, traverses to the tail, and then inserts
Cycle: http://blog.csdn.net/hongkangwl/article/details/22284249
Bidirectional: http://blog.csdn.net/hongkangwl/article/details/22286469

Queue Sqqueue
struct (datatype data[size],ine head,int tail)
Init: Request node space, copy, add pointer
IsEmpty: Judging Head==tail
Isfull:head = = Size
InQueue: Full, copy to tail node, tail subscript +1
Outqueue: empty, queue = head node moves backwards

Linkqueue:
struct node (datatype data,node *next) struct linklist (node Front,node rear)
Init: Initialize head node, rear=front,front->next=null
Inqueue: Initialize the node to be joined, P->data = E,p->next = NULL. LQ->rear->next = P.lq->rear = P.
Outqueue: Determine if NULL, head node p, head node points to P's next, if Delete is tail node, re-fill, release p

Circlequeue:
Stuct{datatype *base,int Front,int Rear}
Init: Request Base node, Header = Tail
Length: (Tail-head +maxsize)%maxsize
In: Whether full tail +1%maxsize= front base[rear]=e,rear= (rear+1)%maxsize, so the maximum value will not be exceeded
De: Empty, e= head, head = Head +1%maxsize

The inverse of the sparse matrix:
Triple (int i,int j,datatype e) Tsmatrix (Triple[size+1],int mu,nu,tu)
Common method: Crpot[size],num[size], new and old matrix row number Exchange, not 0 number assigned to the new matrix, if the number of non-0 elements is not 0,q=1, on the old matrix column traversal, to the three-dimensional table walk, if you encounter one of the columns equal to the forefront,
New ternary group of the row Exchange storage, the new ternary group number plus 1,
Fast method: The new and Old matrix column number Exchange, if there is a non-0 value, the new matrix for each column of a non-0 number of initial value 0, and then traverse the ternary table to get the value of the 0 number of each column, and then get the first element in each column in the ternary table ordinal,
Walk through the old three meta-table, get the column, start loading from the column of the new ternary group, the number of columns +1


Special matrix compression algorithm, generalized table storage structure, recursive algorithm design
Generalized table: {tag, (data,*sublist) A,*next} is implemented on a string basis: {char *ch,int length}hstring
First, the operation of the string:
Strassign: Generates a string T equals chars, if T is not empty, frees the T space, asks for the length of the chars if it is 0,t->ch = null.t->length=0; If the length is not 0, allocates string space, copies the string, length equals the length of the string
Because T is empty, you don't need to apply for a tablespace.
Strcopy: Copy string s to T, if T is not empty, free t space, allocate t space, according to subscript copy string, t length equals s length
Strempty: Length is 0, value is empty
Strcompare: The length is equal when the word typeface minus, the length is not equal when the length big
Strlength:
CLEARSTR: If not empty, free (CH), ch=null length =0
Conct (hstring t,s1,s2), T is empty, not empty free space, T is equal to the sum of S1,S2, apply ch space, plus S1, and then add s2
SUBSTR: (Sub,str,pos,len) the STR from POS to intercept len length as a sub value, determine whether POS and Len is appropriate, if the sub is not empty, free space, if Str is empty, the string is also empty,
If not empty, apply ch space, assign each value, equal length
Initstr:length=0.ch=null
Index: (s,t,pos) if the first POS character in S is followed by the string and T coincident, returns the subscript at the beginning of the coincident, otherwise returns-1, finding only the second equal subscript
Length =s-t+1,i=pos, beginning to intercept the length of T and i++, if equal, return I,
Strinsert: (S,POS.T) the insertion of t,pos in the POS position of S is legal, if the length of T is not 0, the length of the T is requested after the position of the ch,pos, and then inserted T, plus the length of T
Strdelete: (s,pos,len) Start deleting Len length characters at POS position S, Len is legal, Ch[i]=ch[i+len], length minus, space is reduced, realoc
Strreplace: (s,t,v) substituting V for the string equal to T in S, if T is empty, loop for subscript, delete T, insert V
DESTROYSTR: The length of the heap allocation cannot be destroyed,
Strprint:
Operation of a generalized table:
Initlist:*l=null
Sever: (STR,HSTR), divides str into two parts, hstr as the first, before the string, str as the first, followed by the string
c1=, c2= (c3=) n for the original STR length, starts the execution loop {starting from 0 intercepts 1 length strings to the CH, if CH is (, k+1, if CH is), k-1,++i} when satisfied
(i< the original str length and CH is greater than, that is, CH is the letter, | | K!=0, that is, all parentheses do not match) that is, when equal, and traversed to the last stop
If present, give Str and HSTR values, if not present, head = all, tail empty
CreateList: (l,s) s is a generalized table-like string, L is the table to be created,
The application tablespace, if the string is (), creates an empty table, Tag=list,sublist=null,next = null
If the length is 1, create an Atomic generalized table, Tag=atom,atom=ch[0],next=null
In other cases, that is, the general generalized table, Tag=list,next=null. Remove the outer brackets, separate the head, add to the list p, if the tail string is not empty, split again, the head is added to the tail p->next,p=p->next
Destroylist: If the table is not empty, is the atom, the direct =null, is the child table, find sublist,next separate recursive call, delete L first node.
Copylist: (t,l) copy L to get the table t,l is empty, T is also empty, return 1, otherwise the application space for T, copy tag, if it is an atomic table, copy atoms, otherwise, recursive call, copy sublist,
If the footer is empty, copy, otherwise, recursively call, copy footer
Glistlength: If it is an empty table, return 0, if it is an atomic table, return 1, if it is a general table, P-&GT;TP, the number of elements is the outermost parentheses within the number of comma-separated
Glistdepth: If the table is empty or the table's type is list but the table's sublist is empty, return1, if Tag=0,return0.
Otherwise it is the general table, each take the tail, traverse once +1, Max DEP for Max, return max+1
Glistempty: If the table does not exist or the table is a list type but sublist is empty,
GetHead: If it is empty table, no table header, otherwise, request tablespace, copy tag, if atom, copy atom value, if not, copy L->sublist->sublist to value to return
GetTail: If it is empty table, no footer, otherwise, the application table space, assignment tag, copy l->sublist->next, the footer is a chunk Oh, is the first one to intercept, after the second half of the table converted into
Insertfirstlist: Assigning a value to the first element
Deletefirstlist: Returns E, if not empty, e=a.sublist,l->sublist=e->next,e->next=null, if empty, e=l
TRAVERSE_GL: Recursive traversal of GL, if the table is not empty, if it is an atom, if it is a child table, sublist traversal,
Createlistby scanf: All characters entered may be # letters (), one method has two inputs, the first input (, letters, # Because of the input (which then goes into the first input of the next function, so one # and the letter terminates
Second input,)) means that the NEX is null, representing the next value starting input, entering the next method of the first input


Generalized tables and previous pseudo-code

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.