Soft test path-linear table of Data Structure, soft Test Data Structure

Source: Internet
Author: User

Soft test path-linear table of Data Structure, soft Test Data Structure

The data is the value, that is, the result we get through observation, experiment, or calculation. There are many types of data, the simplest of which is numbers. Data can also be text, images, sounds, etc. Data can be used for scientific research, design, verification, and so on. Structure, the overall composition of the various parts of the collocation and arrangement, the two perfect combination, we need to re-understand her, re-examine and define her: data structure is an important theoretical and technical basis for program design. The content and technology she discussed play an important role in the development of software projects. By studying the data structure, we learn to analyze and study the characteristics of data processed by computers from the perspective of problems, so that appropriate logical structures, storage structures, and corresponding operation methods can be mounted to the data designed for applications, to improve the efficiency of application computers in solving problems.

I have been studying the xicai video for a while. In this period of time, self-testing and rank-based tests are mixed. to exaggerate, there are laughter and tears, I laughed at the fact that the two major questions that I got from the grade test yesterday were all original questions. The tears were that there was a blank question and a return question, and I remembered that sentence, it is always necessary to wait for the exam to know that the book to be read has not been read. There are a total of 60 points for the big question. If the Score System in previous years is used, it will take 60% of the total score, that is to say, 60 points should be scored points, but I can only get points for the last question, you can repeat C ++ '(* partition _ partition *)'. Today, I want to explain the data table in the data structure. First, let's take a look at a diagram of the basic data structure:

After learning about the basic data structure, go to the topic linear table today. This blog article focuses on the following:

I. Linear table

Concept:A linear table is the simplest, most basic, and most commonly used linear structure. It has two storage methods: sequential storage and chained storage. The main basic operation is insert, delete and search.

Category:A linear table consists of a sequence table and a chain table. A chain table is divided into a single-chain table, a circular chain table, and a double-chain table for analysis in sequence.

Sequence Table, As shown in:

Sequence Structure: sequence structure is the simplest program structure and the most common program structure. You only need to write the corresponding statements in the order of solving the problem. The execution sequence is from top to bottom, in turn. For a simple example, a = 3, B = 5, and now the values of a and B are exchanged. This problem is like switching two cups of water. Of course, the third cup is used, if the third cup is c, the correct program is: c = a; a = B; B = c; the execution result is a = 5, B = c = 3.

Linked List, As shown in:

Linked List: A linked list is a non-continuous and non-sequential storage structure of physical storage units. The logical sequence of data elements is achieved through the pointer links in the linked list. A linked list consists of a series of nodes (each element in a linked list is called a node), which can be dynamically generated at runtime. Each node consists of two parts: one is the data domain that stores data elements, and the other is the pointer domain that stores the next node address. Compared with the sequential structure of a linear table, the operation is complex.

Category of linked list: Single-chain table, cyclic linked list, and double-chain table. As shown in:

Data Field: stores data; pointer field: stores the address pointing to the next node; Circular linked list: the last node. Her next node is the first node.

Double-linked table: There are two pointer fields that link the linked list from two different directions. A double-linked table can be moved in two directions. A single-linked table moves in one direction. The flexibility of a double-linked table is better than that of a single-linked table. Double-linked tables are more expensive because they have two pointer fields. Deletion and insertion of single and double linked lists: Delete a single-chain table: delete a node. Delete a2. Method: Direct the a1 pointer field to a3. Skip a2. Then a2 is deleted from the linked list, another task is to release a2. Point the next field of the forward node to be deleted to its next node. Insertion of a single-chain table: deleting a node directs the forward order to the back order. inserting a node is a reverse process, where a new node is inserted, point the next field of her forward node to the newly added node, and then point the next field of the newly added node to the next node. Double-chain table deletion and insertion: two aspects are involved: from left to right columns and from right to left columns. It is not a simple chain, but a chain is completed, we need to write out all four steps, complete the first steps of the two operations first, and then proceed to the second step. Sequence Table PK linked list

Ii. Queue

Concept: A queue is a special linear table. It can only be deleted at the front end of the table, but inserted at the back end of the table (rear. The end of the insert operation is called the end of the team, and the end of the delete operation is called the head of the team. When there are no elements in a queue, it is called an empty queue. For example, if you go to the canteen to queue up, you can buy food first, and the team tails come later. When you enter the station, you can check your luggage first, and then you can go in later.

CategoryA queue is a special linear table. It allows you to delete only the front of a table, the insert operation on the table's backend (rear) is similar to the stack, and the queue is a linear table with limited operations. The end of the insert operation is called the end of the team, and the end of the delete operation is called the head of the team. When there are no elements in a queue, it is called an empty queue. In a data structure such as a queue, the first element to be inserted will be the first element to be deleted; the last element to be inserted will be the last element to be deleted, therefore, a queue is also called a linear table of "FIFO-first in first out. For example:

 Ordered queue:

 Cyclic queue:

Ps: the word "Yes" is wrong. Don't laugh.

Iii. Stack

STACK: it is not a real concept. It is a logical concept, an idea, or an idea. Unlike chain storage and sequential storage, it is a node and has a regular pattern, it is based on sequential storage and chained storage, and is a logical concept. Stacks can be implemented either in a chained structure or in an ordered structure-an array. Define a rule first and then go out. As follows:

 Note:A linear table (also called a sequence table) is the most basic, simple, and commonly used data structure. The relationship between data elements in a linear table is one-to-one, that is, except the first and last data elements, other data elements are connected at the beginning and end. The logical structure of a linear table is simple for implementation and operation. Therefore, the linear table data structure is widely used in practical applications. The stack and queue are a special linear table. The road to the soft test is to be continued ......


Data Structure-linear table-how to implement it in VC ++ 60

# Include <iostream. h>
# Include <stdlib. h>
# Include <iostream. h>
Typedef struct seqlist // defines the sequential storage structure of a linear table
{
Int * elem; // The first address allocated to the bucket
Int length; // Linear length
} Seqlist;
// This variable can be used as a linear table data type to define a linear table
Void init (seqlist & l) // initialize a linear table
{
L. elem = new int [20]; // allocate a bucket to store elements in a linear table
L. length = 0; // The length of the empty linear table is 0.
}

Void delseqlist (seqlist & l) // destroy the created linear table
{
Delete [] l. elem;
L. length = 0;
}

Void insert (seqlist & l, int I, int x) // insert element e to position I in the linear table.
{
If (I <1 | I> l. length + 1)
Cout <"I value is invalid! "<Endl; // handle errors
For (int j = l. length; j> = I; j --)
L. elem [j + 1] = l. elem [j]; // the I-th element and its elements are moved back in sequence.
L. elem [I] = x; // Insert the new element at position I.
L. length ++; // The length of the linear table increases by 1.
}

Void printout (seqlist & l) // output all elements in the linear table
{
Int j;
For (j = 1; j <= l. length; j ++)
Cout <l. elem [j] <"";
}

Int llength (seqlist & l) // evaluate the length of a linear table
{
Return l. length;
}

Int locateElem (seqlist & l, int e) // search for the first data element with the same value as e in the sequence table L
{
Int I = 1;
Int * p;
P = l. elem; p ++; // p points to the first element in the linear table.
While (I <= l. length & * p ++! = E) // compare them backward.
++ I;
If (I <= l. length)
Return I;
Else
Return 0; // return results
}

Void Delete (seqlist & l, int I, int & e) // This function deletes the I-th element and returns the value using e.
{
Int * p, * q;
If (I <1) | (I> l. length) cout <& lt ...... remaining full text>

Data structure linear table

Include "stdlib. h"
# Include "stdio. h"

// Basic operations of the sequence table

Bool InitList_Sq (SqList & L) {// Initialization
L. elem = (int *) malloc (LIST_INIT_SIZE * sizeof (int ));
If (! L. elem) exit (1 );
L. length = 0;
L. listsize = LIST_INIT_SIZE;
Return 1;
}

Bool ListInsert_Sq (SqList & L, int I, int e) {// algorithm 2.4
// Insert a new element e before the I element of the ordered linear table L,
// The valid value of I is 1 ≤ I ≤ ListLength_Sq (L) + 1
Int * p;
If (I <1 | I> L. length + 1) return false; // The I value is invalid.
If (L. length> = L. listsize) {// The current bucket is full and the capacity is increased
Int * newbase = (int *) realloc (L. elem,
(L. listsize + LISTINCREMENT) * sizeof (int ));
If (! Newbase) return false; // storage allocation failed
L. elem = newbase; // new base address
L. listsize + = LISTINCREMENT; // increase the storage capacity
}
Int * q = & (L. elem [I-1]); // q is the insert position
For (p = & (L. elem [L. length-1]); p> = q; -- p) * (p + 1) = * p;
// Right shift of the inserted position and subsequent elements
* Q = e; // insert e
+ L. length; // The table length increases by 1.
Return true;
} // ListInsert_Sq

Void printList_Sq (SqList L) {// Note: 1. the parameter is L, not & L; 2. This function is an extended operation.
If (L. length> 0 ){
Int I = 1;
Printf ("the order of elements is :");
For (I = 1; I <L. length + 1; I ++ ){
Printf ("% d", L. elem [I-1]);
}
Printf ("\ n ");
}
}... Remaining full text>

Related Article

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.