Put my C homework to experimentally a linear table

xiaoxiao2021-03-06  38

Put my job out to experimentally a linear table, the experimental purpose 1. Familiar with the order of linear forms and chain storage structure 2. Master the basic operation of the linear table 3. The calculation of linear table applications can be used to use the basic operation of the linear table

Second, the experimental purpose 1. It is provided with a linear table E = {E1, E2, ..., EN-1, En}, design a algorithm, reverse the linear table, even if the element is arranged in the order, become a reverse linear table E '= {EN, EN- 1, ..., E2, E1}, require the reverse linear table to occupy the original linear table space, and use two methods and single-stranded tables to be done with two programs. (Folder: exercise 9_3)

2. It is known from the linear table indicated by a single-chain table indicated by the head node, contains three types of characters (letters, numbers, and other characters), and the test cells construct three linear tables represented by the circular chain list, so that each Only characters in the table contain the same class, and use the node space in the original table, the head node can also open a space. (Folder: exercise 9_12)

first question

/ * Structure type definition of sequence table. H * /

Typedef char dattype;

/ * const amount = 1024; * /

#define maxSize 1024

Typedef struct

{Datatype Data [MAXSIZE];

Int last;

} sequence;

#include #include #include #include "sequence table structure type definition .h"

INT main () {sequence * L; L = Creat (L); PUTS ("Original String: / N"); Print (L); Invert (L); / * Call sequence table inverse value function * / PUTS ("String: / n"); Print (L); System ("Pause");} / * Output Sequence Meter .h * / # include #include #include #include "Sequence Table Structure Type Definition .h"

Void print (sequence * L) {INT i; for (i = 0; i last; i ) / * cout << l-> data [i] << "; cout << endl; * / Printf ("% C", L-> DATA [I]); PUTS ("/ N"); return;}

/ * Establish a sequence table. H * / # include "Sequence Table Structure Type Definition .h" #include #include sequence * creat (sequence * l) {char ch; l = (SequenceList *) Malloc (SIZEOF (SEQUENLIST)); L-> Last = 0; PUTS ("Please enter a string (input" * "end): / n"); while ((ch = getchar ())! = ' * ') {L-> Data [l-> last] = ch; l-> Last ;} returnit} / * This program cannot ignore the carriage return, there is a return of the *, will also be in the corresponding position Output a carriage return * /

// Second question / * Single-link table structure type definition. H * / typef char Dattype; typef struct node {datatype data; struct node * next;} linklist; / * Single-lapse list inverse primary file .cpp * / # include < Stdafx.h> #include #include #include "single-chain table structure type definition .h" int main () {linkList * Head; head = creat (head); / * original C The write function is to transmit the value in a reference method, C does not support, add the return value * / PUTS ("The string you entered is:"); print (head); invert (head); / * call single Link list The function * / PUTS ("The inverse string is:"); Print (Head); getch (); return 1;} / * established single-link table. H * / # include #include #include #include "single-chain table structure type definition .H" LinkList * Creat (Linklist * Head) / * Established a single-link table with head node * / { Char ch ;LinkList * S, * R; head = (linklist *) malloc (limited)); r = head; PUTS ("Please enter the string (" * "end):"); while ((chile) = getChar ())! = '*') {s = (linklist *) malloc (limited)); s-> data = ch; r-> next = s; r = s;} r-> Next = NULL; RETURN Head;} ​​/ * Output Single List. H * / # include #include #include #include "single-chain table structure type definition .h" Void Print Linklist * p = head-> next; while (p! = null) {/ * cout << p-> data << "; * / printf ("% c ", p-> data) ; P = p-> next;} / * couch T << endl; * / puts ("/ n");} / * Single-link table inversion * / # include #include #include #include "single-link list Structural type definition .h "

转载请注明原文地址:https://www.9cbs.com/read-77410.html

New Post(0)