0% found this document useful (0 votes)
9 views50 pages

Data Structures and Problem Solving Using C 2nd International Edition Edition Mark Allen Weiss

The document provides information on various ebooks and textbooks related to data structures and problem solving using C and C++. It includes links to download specific editions of books by authors like Mark Allen Weiss and others, along with details about the content covered in these books. Additionally, it contains copyright information and a brief overview of the structure of the books, including chapters on algorithms, object-oriented programming, and design patterns.

Uploaded by

nukaritionha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views50 pages

Data Structures and Problem Solving Using C 2nd International Edition Edition Mark Allen Weiss

The document provides information on various ebooks and textbooks related to data structures and problem solving using C and C++. It includes links to download specific editions of books by authors like Mark Allen Weiss and others, along with details about the content covered in these books. Additionally, it contains copyright information and a brief overview of the structure of the books, including chapters on algorithms, object-oriented programming, and design patterns.

Uploaded by

nukaritionha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Visit https://ebookultra.

com to download the full version and


explore more ebooks or textbooks

Data Structures And Problem Solving Using C 2nd


International Edition Edition Mark Allen Weiss

_____ Click the link below to download _____


https://ebookultra.com/download/data-structures-and-problem-
solving-using-c-2nd-international-edition-edition-mark-
allen-weiss/

Explore and download more ebooks or textbooks at ebookultra.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Data Structures and Problem Solving Using Java 4th,


intern. Edition Weiss

https://ebookultra.com/download/data-structures-and-problem-solving-
using-java-4th-intern-edition-weiss/

Object Orientation Abstraction and Data Structures Using


Scala 2nd Edition Edition Mark C. Lewis

https://ebookultra.com/download/object-orientation-abstraction-and-
data-structures-using-scala-2nd-edition-edition-mark-c-lewis/

Data structure and algorithm analysis C language English 2


Adapted China Edition Mark Allen Weiss

https://ebookultra.com/download/data-structure-and-algorithm-analysis-
c-language-english-2-adapted-china-edition-mark-allen-weiss/

Data Structures Using C C 2nd Edition Edition Aaron M.


Tenebaum

https://ebookultra.com/download/data-structures-using-c-c-2nd-edition-
edition-aaron-m-tenebaum/
Data structures using C 1st Edition Patil

https://ebookultra.com/download/data-structures-using-c-1st-edition-
patil/

Data Abstraction Problem Solving with C 6th Edition Frank


M. Carrano

https://ebookultra.com/download/data-abstraction-problem-solving-
with-c-6th-edition-frank-m-carrano/

Objects Abstraction Data Structures and Design Using C 1st


Edition Elliot B. Koffman

https://ebookultra.com/download/objects-abstraction-data-structures-
and-design-using-c-1st-edition-elliot-b-koffman/

Problem Solving with C 6th Edition Savitch

https://ebookultra.com/download/problem-solving-with-c-6th-edition-
savitch/

Data structures and algorithm analysis in C Fourth


Edition, International Edition / Chandavarkar

https://ebookultra.com/download/data-structures-and-algorithm-
analysis-in-c-fourth-edition-international-edition-chandavarkar/
Data Structures And Problem Solving Using C 2nd
International Edition Edition Mark Allen Weiss Digital
Instant Download
Author(s): Mark Allen Weiss
ISBN(s): 9780321205001, 0321205006
Edition: 2nd International Edition
File Details: PDF, 41.20 MB
Year: 2003
Language: english
DATA STRUCTURES AND
PROBLEM SOLVING USING C++
Second Edition

MARK ALLEN WElSS


Florida International U n i v e r s i ~

Pearson Education International Inc., Upper Saddle River, N.J. 07458


If you purchased this book within the United States or Canada
you should be aware that it has been wrongfully imported
without the approval of the Publisher or the Author.

Acquisitions Editor: Susan Hartman


Project Editor: Katherine Harutunian
Production Management: Shepherd, lnc.
Composition: Shepherd. Inc.
Cover Design: Diana Coe
Cover Photo: O Mike ShepherdPhotonica

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks.
Where those designations appear in this book, and the publisher was aware of a trademark claim. the des~gnationshave
been printed in ~nitialcaps or in all caps.

The programs and the applications presented In this book have been included for their instruct~onalvalue. They have
been tested with care but are not guaranteed for any particular purpose. Neither the publisher or the author offers any
warranties or representations. nor do they accept any liabilities with respect to the programs or applications.

@Copyright 2003 Pearson Education International


Upper Saddle River. N.J. 04758
@Copyright 2002 by Addison Wesley Longman, Inc.

All rights reserved. No part of this publication may be reproduced. stored In a database or retrieval system.
or transmitted in any form or by any means. electronic, mechanical, photocopying, recording. or any other
media embodiments now known or hereafter to become known. without the prior written permis5lon of the
publisher. Printed in the United States of Amenca.

ISBN: 0321 205006

10987654321
I Contents

Part I: Objects and C++

Chapter 1 Arrays, Pointers, and Structures 3


I .I What Are Pointers, Arrays, and Structures? 3
1.2 Arrays and Strings 4
1.2.1 First-Class Versus Second-Class Objects 4
1.2.2 Using the vector 6
1.2.3 Resizing a vector 7
1.2.4 gush-back:sizeandcapacity 1 1
1.2.5 Parameter-Passing Mechanisms 1 1
1.2.6 Primitive Arrays of Constants 13
1.2.7 Multidimensional Arrays 14
1.2.8 TheStandardLibrarystringType 14
1.3 Pointer Syntax in C++ 15
1.4 Dynamic Memory Management 20
1.4.1 The new Operator 2 1
I .4.2 Garbage Collection and delete 21
1.4.3 Stale Pointers, Double Deletion, and More 22
1.5 Reference Variables 24
1.6 Structures 26
1.6.1 Pointers to Structures 28
1.6.2 Exogenous Versus Indigenous Data and Shallow Versus Deep
Copying 29
1.6.3 Noncontiguous Lists: Linked Lists 30
Summary 32
Objects of the Game 32
Common Errors 34
On the Internet 35
Exercises 35
References 38
Chapter 2 Objects and Classes 41
2.1 What Is Object-Oriented Programming? 4 1
2.2 Basic class Syntax 43
2.2.1 Class Members 43
2.2.2 Extra Constructor Syntax and Accessors 45
2.2.3 Separation of Interface and Implementation 48
2.2.4 The Big Three: Destructor, Copy Constructor, and
operator= 51
2.2.5 Default Constructor 57
2.3 Additional C++ Class Features 57
2.3.1 Initialization Versus Assignment in the Constructor
Revisited 61
2.3.2 Type Conversions 63
2.3.3 Operator Overloading 64
2.3.4 Input and Output and Friends 67
2.4 Some Common Idioms 68
2.4.1 Avoiding Friends 70
2.4.2 Static Class Members 7 I
2.4.3 The enum Trick for Integer Class Constants 71
2.5 Exceptions 72
2.6 A string Class 73
2.7 Recap: What Gets Called and What Are the Defaults? 82
2.8 Composition 84
Summary 85
Objects of the Game 85
Common Errors 87
On the Internet 89
Exercises 90
References 96

Chapter 3 Templates 97
3.1 What Is a Template? 97
3.2 Function Templates 98
3.3 A Sorting Function Template 100
3.4 Class Templates 103
3.4.1 A MemoryCell Template 103
3.4.2 Implementing the vector Class Template 108
3.5 Templates of Templates: A matrix Class 108
3.5.1 The Data Members, Constructor. and Basic Accessors 1 1 1
3.5.2 operator [ I 112
3.5.3 Destructor, Copy Assignment, and Copy Constructor 112
--
Contents

3.6 Fancy Templates 1 12


3.6.1 Multiple Template Parameters 1 12
3.6.2 Default Template Parameters 1 13
3.6.3 The Reserved Word typename 1 13
3.7 Bugs Associated with Templates 1 14
3.7.1 Bad Error Messages and Inconsistent Rules 1 14
3.7.2 Template-Matching Algorithms 1 14
3.7.3 Nested Classes in a Template 114
3.7.4 Static Members in Class Templates 1 15
Summary 1 15
Objects of the Game 1 15
Common Errors 1 15
On the Internet 1 16
Exercises 1 17

Chapter 4 Inheritance 119


4. I What Is Inheritance? 1 19
4.2 Inheritance Basics 123
4.2.1 Visibility Rules 124
4.2.2 The Constructor and Base Class Initialization 125
4.2.3 Adding Members 126
4.2.4 Overriding a Method 128
4.2.5 Static and Dynamic Binding 129
4.2.6 The Default Constructor, Copy Constructor, Copy Assignment
Operator, and Destructor 13 1
4.2.7 Constructors and Destructors: Virtual or Not Virtual? 132
4.2.8 Abstract Methods and Classes 133
4.3 Example: Expanding the Shape Class 136
4.4 Tricky C++ Details 142
4.4.1 Static Binding of Parameters 142
4.4.2 Default Parameters 143
4.4.3 Derived Class Methods Hide Base Class Methods 144
4.4.4 Compatible Return Types for Overridden Methods 145
4.4.5 Private Inheritance 146
4.4.6 Friends 146
4.4.7 Call by Value and Polymorphism Do Not Mix 146
4.5 Multiple Inheritance 147
Summary 149
Objects of the Game 149
Common Errors 150
On the Internet 152
Exercises 152
R e f e r e n c e s 154
- - -
- - -- - - - - - - - - - -
Chapter 5 Design Patterns 155
5.1 What Is a Pattern'? 155
5.2 The Functor (Function Objects) 156
5.3 Adapters and Wrappers 162
5.3.1 Wrapper for Pointers 162
5.3.2 A Constant Reference Wrapper 168
5.3.3 Adapters: Changing an Interface 169
5.4 lterators 170
5.4.1 Iterator Design 1 171
5.4.2 Iterator Design 2 174
5.4.3 Inheritance-Based Iterators and Factories 174
5.5 Composite (Pair) 179
5.6 Observer 179
Summary 184
Objects of the Game 184
Common Errors 185
On the Internet 186
Exercises 186
References 190

Part ZI: Algorithms and Building Blocks

Chapter 6 Algorithm Analysis 193


6.1 What Is Algorithm Analysis? 193
6.2 Examples of Algorithm Running Times 198
6.3 The Maximum Contiguous Subsequence Sum Problem 199
6.3.1 The Obvious O(N3) Algorithm 200
6.3.2 An Improved O(N2) Algorithm 203
6.3.3 A Linear Algorithm 204
6.4 General Big-Oh Rules 206
6.5 The Logarithm 2 1 1
6.6 Static Searching Problem 21 4
6.6.1 Sequential Search 2 14
6.6.2 Binary Search 215
6.6.3 Interpolation Search 217
6.7 Checking an Algorithm Analysis 2 19
6.8 Limitations of Big-Oh Analysis 220
Contents

Summary 221
Objects of the Game 22 1
Common Errors 222
On the Internet 223
Exercises 223
References 228

Chapter 7 The Standard Template Library 231


7.1 Introduction 232
7.2 Stacks and Queues 233
7.2.1 Stacks 233
7.2.2 Stacks and Computer Languages 235
7.2.3 Queues 236
7.3 Containers and Iterators 237
7.3.1 Containers 238
7.3.2 The i t e r a t o r 238
7.4 STL Algorithms 240
7.4.1 STL Function Objects 240
7.4.2 Binary Search 243
7.4.3 Sorting 244
7.5 Implementation of vector with an Iterator 245
7.6 Sequences and Linked Lists 247
7.6.1 T h e l i s t c l a s s 247
7.6.2 Stacks and Queues 249
7.7 Sets 249
7.8 Maps 251
7.9 Priority Queues 253
Summary 257
Objects of the Game 257
Common Errors 259
On the Internet 259
Exercises 260
References 264

Chapter 8 Recursion 265


8.1 What Is Recursion? 265
8.2 Background: Proofs by Mathematical Induction 267
8.3 Basic Recursion 269
8.3.1 Printing Numbers in Any Base 27 1
8.3.2 Why It Works 274
8.3.3 How It Works 275
8.3.4 Too Much Recursion Can Be Dangerous 276
8.3.5 Preview of Trees 278
8.3.6 Additional Examples 279
8.4 Numerical Applications 284
8.4.1 Modular Arithmetic 285
8.4.2 Modular Exponentiation 285
8.4.3 Greatest Common Divisor and Multiplicative Inverses 287
8.4.4 The RSA Cryptosystem 289
8.5 Divide-and-Conquer Algorithms 292
8.5.1 The Maximum Contiguous Subsequence Sum Problem 293
8.5.2 Analysis of a Basic Divide-and-Conquer Recurrence 297
8.5.3 A General Upper Bound for Divide-and-Conquer Running
Times 301
8.6 Dynamic Programming 303
8.7 Backtracking 308
Summary 3 10
Objects of the Game 3 12
Common Errors 3 13
On the Internet 3 14
Exercises 3 14
References 3 19

Chapter 9 Sorting Algorithms 321


9.1 Why Is Sorting Important? 322
9.2 Preliminaries 323
9.3 Analysis of the Insertion Sort and Other Simple Sorts 324
9.4 Shellsort 326
9.4.1 Performance of Shellsort 328
9.5 Mergesort 330
9.5.1 Linear-Time Merging of Sorted Arrays 330
9.5.2 The Mergesort Algorithm 332
9.6 Quicksort 334
9.6.1 The Quicksort Algorithm 335
9.6.2 Analysis of Quicksort 337
9.6.3 Picking the Pivot 340
9.6.4 A Partitioning Strategy 342
9.6.5 Keys Equal to the Pivot 344
9.6.6 Median-of-Three Partitioning 345
9.6.7 Small Arrays 346
9.6.8 C++ Quicksort Routine 346
9.7 Quickselect 348
9.8 A Lower Bound for Sorting 349
9.9 Indirect Sorting 352
9.9.1 Using Pointers to Reduce Comparable Copies to 2N 352
9.9.2 Avoiding the Extra Array 353
Summary 355
Objects of the Game 356
Common Errors 357
On the Internet 357
Exercises 358
References 363

Chapter 10 Randomization 365


10.1 Why Do We Need Random Numbers? 365
10.2 Random Number Generators 366
10.3 Nonuniform Random Numbers 37 1
10.4 Generating a Random Permutation 373
10.5 Randomized Algorithms 375
10.6 Randomized Prjmality Testing 378
Summary 380
Objects of the Game 382
Common Errors 383
On the Internet 383
Exercises 383
References 386

Part I l l : Applications

Chapter 11 Fun and Games 389


1 1.1 Word Search Puzzles 389
11.1.1 Theory 390
1 1.1.2 C++ Implementation 39 1
1 1.2 The Game of Tic-Tac-Toe 395
I 1.2.1 Alpha-Beta Pruning 397
I 1.2.2 Transposition Tables 398
1 1.2.3 Computer Chess 404
Summary 405
Objects of the Game 405
-- - .-A

Contents

Common Errors 406


On the Internet 406
Exercises 406
References 408

Chapter 12 Stacks and Compilers 409


12.1 Balanced-Symbol Checker 409
12.1.I Basic Algorithm 409
12.1.2 Implementation 4 1 1
12.2 A Simple Calculator 420
12.2.1 Postfix Machines 421
12.2.2 Infix to Postfix Conversion 422
12.2.3 Implementation 424
12.2.4 Expression Trees 432
Summary 435
Objects of the Game 435
Common Errors 436
On the Internet 436
Exercises 436
References 438

Chapter 13 Utilities 439


13.1 File Compression 439
13.1.1 Prefix Codes 440
13.1.2 Huffman's Algorithm 442
13.1.3 Implementation 445
13.2 A Cross-Reference Generator 46 1
13.2.1 Basic Ideas 46 1
13.2.2 C++ Implementation 462
Summary 466
Objects of the Game 466
Common Errors 466
On the Internet 467
Exercises 467
References 470

Chapter 14 Simulation 471


14.1 The Josephus Problem 47 1
14.l . l The Simple Solution 473
14.1.2 A More Efficient Algorithm 473
14.2 Event-Driven Simulation 475
14.2.1 Basic Ideas 477
14.2.2 Example: A Modem Bank Simulation 478
Summary 486
Objects of the Game 486
Common Errors 486
On the Internet 486
Exercises 486

Chapter 15 Graphs and Paths 489


15.1 Definitions 489
15.1.1 Representation 49 1
15.2 Unweighted Shortest-Path Problem 503
15.2.1 Theory 504
1 5.2.2 C++ Implementation 509
15.3 Positive-Weighted, Shortest-Path Problem 509
15.3.1 Theory: Dijkstra's Algorithm 509
15.3.2 C++ Implementation 5 13
15.4 Negative-Weighted. Shortest-Path Problem 5 14
15.4.1 Theory 514
15.4.2 C++ Implementation 5 17
15.5 Path Problems in Acyclic Graphs 5 17
15.5.1 Topological Sorting 5 17
15.5.2 Theory of the Acyclic Shortest-Path Algorithm 520
15.5.3 C++ Implementation 522
15.5.4 An Application: Critical-Path Analysis 522
Summary 526
Objects of the Game 527
Common Errors 528
On the Internet 529
Exercises 529
References 533

Part ZV: Zmplementations

Chapter 16 Stacks and Queues 537


16.1 Dynamic Array Implementations 537
16.1.1 Stacks 538
16.1.2 Queues 541
16.2 Linked List Implementations 548
16.2.1 Stacks 548
16.2.2 Queues 553
16.3 Comparison of the Two Methods 557
16.4 The STL Stack and Queue Adapters 558
16.5 Double-Ended Queues 558
Summary 559
Objects of the Game 56 1
Common Errors 561
On the Internet 56 1
Exercises 562

Chapter 17 Linked Lists 565


17.1 Basic Ideas 565
17.1.1 Header Nodes 567
17.1.2 Iterator Classes 569
17.2 C++ Implementation 570
17.3 Doubly Linked Lists and Circularly Linked Lists 579
17.4 Sorted Linked Lists 582
17.5 lmplementingtheSTLlistClass 582
Summary 597
Objects of the Game 597
Common Errors 598
On the Internet 598
Exercises 599

Chapter I 8 Trees 605


18.1 General Trees 605
18.1.1 Definitions 605
1 8.1.2 Implementation 607
1 8.1.3 An Application: File Systems 608
18.2 Binary Trees 61 1
18.3 Recursion and Trees 6 19
18.4 Tree Traversal: lterator Classes 622
18.4.1 Postorder Traversal 624
18.4.2 Inorder Traversal 630
18.4.3 Preorder Traversal 630
18.4.4 Level-Order Traversals 630
Summary 633
Objects of the Game 636
Common Errors 637
On the Internet 637
Exercises 637

Chapter 19 Binary Search Trees 641


19.1 Basic Ideas 64 1
19.1.1 The Operations 642
19.1.2 C++ lmplementation 644
19.2 Order Statistics 652
19.2.1 C++ Implementation 653
19.3 Analysis of Binary Search Tree Operations 657
19.4 AVL Trees 661
19.4.1 Properties 662
19.4.2 Single Rotation 664
19.4.3 Double Rotation 667
19.4.4 Summary of AVL Insertion 670
19.5 Red-Black Trees 670
19.5.1 Bottom-Up Insertion 672
19.5.2 Top-Down Red-Black Trees 674
19.5.3 C++ Implementation 676
19.5.4 Top-Down Deletion 680
19.6 AA-Trees 685
19.6.1 Insertion 686
19.6.2 Deletion 688
19.6.3 C++ Implementation 690
19.7 Implementing the STL set and map Classes 693
19.8 B-Trees 707
Summary 714
Objects of the Game 7 15
Common Errors 7 17
On the Internet 7 17
Exercises 7 18
References 72 1

Chapter 20 Hash Tables 725


20.1 Basic Ideas 725
20.2 Hash Function 727
20.3 Linear Probing 729
20.3.1 Naive Analysis of Linear Probing 73 1
20.3.2 What Really Happens: Primary Clustering 732
20.3.3 Analysis of the find Operation 733
20.4 Quadratic Probing 735
20.4.1 C++ Implementation 739
20.4.2 Analysis of Quadratic Probing 745
20.5 Separate Chaining Hashing 746
20.6 Hash Tables Versus Binary Search Trees 746
20.7 Hashing Applications 747
Summary 747
Objects of the Game 748
Common Errors 749
On the Internet 749
Exercises 749
References 752

Chapter 21 A Priority Queue: The Binary Heap 755


21.1 Basic Ideas 755
2 1.1.1 Structure Property 756
2 1.1.2 Heap-Order Property 758
2 1.1.3 Allowed Operations 759
21.2 Implementation of the Basic Operations 761
2 1.2.1 The insert Operation 762
21.2.2 The deleteMin Operation 763
2 1.3 The buildHeap Operation: Linear-Time Heap Construction 766
21.4 STL priority-queue lmplementation 77 1
21.5 Advanced Operations: decreaseKey and merge 773
2 1.6 Internal Sorting: Heapsort 773
2 1.7 External Sorting 778
21.7.1 Why We Need New Algorithms 778
2 1.7.2 Model for External Sorting 778
21.7.3 The Simple Algorithm 779
2 1.7.4 Multiway Merge 78 1
2 1.7.5 Polyphase Merge 782
21.7.6 Replacement Selection 783
Summary 785
Objects of the Game 785
Common Errors 786
On the Internet 787
Exercises 787
References 79 1
Part V: Advanced Data Structures

Chapter 22 Splay Trees 795


22.1 Self-Adjustment and Amortized Analysis 795
22.1 .I Amortized Time Bounds 797
22.1.2 A Simple Self-Adjusting Strategy (That Does Not Work) 797
22.2 The Basic Bottom-Up Splay Tree 799
22.3 Basic Splay Tree Operations 802
22.4 Analysis of Bottom-Up Splaying 803
22.4.1 Proof of the Splaying Bound 806
22.5 Top-Down Splay Trees 809
22.6 Implementation of Top-Down Splay Trees 81 2
22.7 Comparison of the Splay Tree with Other Search Trees 8 18
Summary 8 19
Objects of the Game 8 19
Common Errors 820
On the Internet 820
Exercises 820
References 822

Chapter 23 Merging Priority Queues 823


23.1 The Skew Heap 823
23.1.1 Merging Is Fundamental 823
23.1.2 Simplistic Merging of Heap-Ordered Trees 824
23.1.3 The Skew Heap: A Simple Modification 825
23.1.4 Analysis of the Skew Heap 826
23.2 The Pairing Heap 828
23.2.1 Pairing Heap Operations 829
23.2.2 Implementation of the Pairing Heap 830
23.2.3 Application: Dijkstra's Shortest Weighted Path Algorithm 836
Summary 840
Objects of the Game 840
Common Errors 84 1
On the Internet 84 1
Exercises 84 1
References 842

Chapter 24 The Disjoint Set Class 845


24.1 Equivalence Relations 845
24.2 Dynamic Equivalence and Two Applications 846
- - - - ----

contents

24.2.1 Application: Generating Mazes 847


24.2.2 Application: Minimum Spanning Trees 850
24.2.3 Application: The Nearest Common Ancestor Problem 853
24.3 The Quick-Find Algorithm 857
24.4 The Quick-Union Algorithm 858
24.4.1 Smart Union Algorithms 860
24.4.2 Path Compression 862
24.5 C++ Implementation 863
24.6 Worst Case for Union-by-Rank and Path Compression 865
24.6.1 Analysis of the UnionIFind Algorithm 866
Summary 873
Objects of the Game 873
Common Errors 875
On the Internet 875
Exercises 875
References 877

Appendices

Appendix A Miscellaneous C++ Details A-3


A. 1 None of the Compilers Implement the Standard A-3
A.2 Unusual C++ Operators A-4
A.2.1 Autoincrement and Autodecrement Operators A-4
A.2.2 Type Conversions A-5
A.2.3 Bitwise Operators A-6
A.2.4 The Conditional Operator A-8
A.3 Command-Line Arguments A-8
A.4 Input and Output A-9
A.4.1 Basic Stream Operations A-9
A.4.2 Sequential Files A- 13
A.4.3 String Streams A- 13
A.5 Namespaces A-15
A.6 New C++ Features A- 17
Common C++ Errors A- 17
Appendix B Operators A-21

Appendix C Some Library Routines A-23


C.l Routines Declared in <ctype. h> and <cctype> A-23
C.2 Constants Declared in <limits. h> and <climits> A-24
C.3 Routines Declared in <math.h> and <cmath> A-25
C.4 Routines Declared in <stdlib.h> and <cstdlib> A-26

Appendix D Primitive Arrays in C++ A-27


D.1 Primitive Arrays A-27
D. 1 . 1 The C++ Implementation: An Array Name Is a Pointer A-28
D. 1.2 Multidimensional Arrays A-3 1
D. I .3 The char * Type, const Pointers, and Constant Strings A-3 I
D.2 Dynamic Allocation of Arrays: new [ ] and delete [ I A-35
D.3 Pointer Arithmetic, Pointer Hopping, and Primitive Iteration A-4 1
D.3.1 Implications of the Precedence of *, &, and [ I A-41
D.3.2 What Pointer Arithmetic Means A-42
D.3.3 A Pointer-Hopping Example A-44
D.3.4 Is Pointer Hopping Worthwhile? A-45
Common C++ Errors A-47
On the Internet A-47
I Preface

This book is designed for a two-semester sequence in computer science,


beginning with what is typically known as Data Structures (CS-2) and con-
tinuing with advanced data structures and algorithm analysis.
The content of the CS-2 course has been evolving for some time.
Although there is some general consensus concerning topic coverage, con-
siderable disagreement still exists over the details. One uniformly accepted
topic is principles of software development, most notably the concepts of
encapsulation and information hiding. Algorithmically, all CS-2 courses
tend to include an introduction to running-time analysis, recursion, basic
sorting algorithms, and elementary data structures. An advanced course is
offered at many universities that covers topics in data structures, algorithms,
and running-time analysis at a higher level. The material in this text has been
designed for use in both levels of courses, thus eliminating the need to pur-
chase a second textbook.
Although the most passionate debates in CS-2 revolve around the choice
of a programming language, other fundamental choices need to be made,
including

whether to introduce object-oriented design or object-based design


early,
the level of mathematical rigor,
the appropriate balance between the implementation of data struc-
tures and their use, and
programming details related to the language chosen.

My goal in writing this text was to provide a practical introduction to


data structures and algorithms from the viewpoint of abstract thinking and
problem solving. I tried to cover all of the important details concerning the
data structures, their analyses, and their C++ implementations, while staying
Other documents randomly have
different content
It must be evident that if this first reason for the failure of the lance
and sword given by Sir John French is valid, it would be needless to
proffer any others. And the others he does proffer only demonstrate
further the weakness of his case. "Secondly," he says, "the war in
South Africa was one for the conquest and annexation of immense
districts, and no settlement was open to us except the complete
submission of our gallant enemy." Such a campaign, he goes on to
say, "is the most difficult that can be confided to an army," etc.
Perfectly true—we agree; but what bearing has this obvious truth on
the combat value of the lance and sword?
The issue before us is this: Is a certain mode of fighting possible in
modern days? Is it practicable for men to remain in their saddles and
wield steel weapons against men armed with modern rifles? "No,"
answers Sir John French, "it is not practicable, if your aim is
annexation and the complete submission of a gallant enemy." Poor
consolation for the unhappy taxpayer who pays for the maintenance
of exceedingly expensive mounted troops, and commits himself to a
scheme of conquest and annexation in the faith that these troops
are efficient instruments of his will! Where would Sir John French's
argument lead him, if he only followed it up and supplied the
missing links? But that is the worst of this interminable controversy.
Such nebulous arguments never are worked out in terms of actual
combat on the battle-field.
Thirdly, says Sir John French, the horses were at fault. "We did not
possess any means for remounting our Cavalry with trained
horses...." "After the capture, in rear of the army, of the great
convoy by De Wet, our horses were on short commons, and
consequently lost condition, and never completely recovered it." This
is an old argument, expressed in the old vague, misleading way. The
war lasted nearly three years, beginning in October, 1899. The
period referred to by Sir John French was in February, 1900. Long
before this, when there was no complaint about the horses, the
futility of the lance and sword, and the grave disabilities under which
the Cavalry laboured owing to their inadequate carbine, had been
abundantly manifest. The steel weapons may be said to have been
obsolete after Elandslaagte, on the second day of the war.
At the particular period referred to by Sir John French—the period of
the operations against Cronje and Kimberley—heat and drought did
undoubtedly play havoc with all the horses in both armies, with
those not only of the Cavalry, but of the mounted riflemen and
Artillery on both sides. In February, 1900, a third of Cronje's small
force was on foot, a pretty severe disability, since his whole force
was scarcely equal to our Cavalry division alone, with its gunners
and mounted riflemen included, while it was less than a quarter as
strong as the whole army at the disposal of Lord Roberts. Sir John
French makes use of a misleading expression when he says that "the
Cavalry horses lost condition, and never completely recovered it."
Nine-tenths of the horses here referred to succumbed altogether
within a few months, and the Cavalry, like nearly all the mounted
troops engaged in the operations in question, were completely
remounted in June, for the grand advance from Bloemfontein to
Pretoria.
During the succeeding two years of warfare all the mounted troops,
Cavalry included, were several times remounted. So were the Boer
troops, who, of course, had no remount organization at all for
"trained" or untrained horses, and had to be content with anything
they could pick up on the veldt. Yet, besides imposing fire-tactics on
the Cavalry in every type of combat alike, they invaded the
traditional sphere of Cavalry (and were imitated to some extent by
our own Colonials and Mounted Infantry) by developing on their own
account a most formidable type of mounted charge, which during
the last year of the war alone cost us 18 guns and 2,500 men killed,
wounded, and prisoners. These charges were made with little rats of
starveling ponies, whose extreme speed was scarcely that of the
slow canter of an ordinary Cavalry charger.
If Sir J. French were to descend to statistics and facts, he would find
it impossible to trace any causal relation between the efficacy of the
lance and sword and the condition of the horses from time to time.
The phenomena are precisely the same under all conditions from
first to last. Everywhere and always the rifle is supreme. The better
the horse, the better help for the rifle—that is all. In point of fact, he
is quite aware that the principal success of the regular Cavalry was
achieved when the horses were at their worst—that is to say, in the
very period he refers to, when the Cavalry headed off Cronje and
pinned him, purely by fire-action, to the river-bed at Paardeberg.
Another good performance—though it was by no means specially a
Cavalry performance; for mounted riflemen and Infantry were
associated with the Cavalry—was the prolonged screening operations
in front of Colesberg (November to January, 1900). There was no
complaint about the horses then, but the sabre never killed or hurt a
Boer. It was only once drawn from the scabbard, and was speedily
resheathed, owing to hostile fire.
I pass to the last and strangest of Sir John French's reasons for
regarding the war as abnormal in the sense that it gave no
opportunity for the use of the lance or sword. It is this: That, "owing
to repeated and wholesale release of prisoners who had been
captured and subsequently appeared in the field against us, we were
called upon to fight, not 86,000 or 87,000 men, but something like
double that number or more, with the additional disadvantage that
the enemy possessed on his second and third appearance against us
considerable experience of our methods and a certain additional
seasoned fitness." Here again is a proposition which alone is
sufficient to destroy the case for the lance and sword. If, as a
defence of those weapons, it means anything, it must mean that the
Cavalry, by means of their steel weapons, were perpetually taking
prisoners, to no purpose, because these prisoners were constantly
released. Gradually the enemy learnt "experience of our methods,"
that is, of our shock-methods with the lance and sword, and, armed
with this experience and the "seasoned fitness" produced by
successive spells of fighting, they eventually countered or evaded
those shock-methods, with what result we are not told. But such an
interpretation is inadmissible. What Sir John French surely should
say is precisely the reverse of what he does imply—namely, that we
started the war in an ignorance of the Boer methods which cost us
scores of millions of pounds; that we slowly learnt experience of
those methods, and ultimately conquered the Boers and ended the
war by imitating those methods. That is the plain moral of the war,
as enforced by every historian.
Observe that, for the sake of argument, I am accepting as
historically accurate Sir John French's statement about the
advantage possessed by the Boers owing to the release of their
prisoners. It is almost superfluous to add that the statement, in the
sense he uses it, has no historical foundation. The truth is exactly
the opposite. The advantage was immensely on our side. The Boers
took many thousands of British prisoners, but permanently retained
none, because they had no means of retaining them. During the last
year of the war prisoners were released on the spot. A large
proportion of these men fought again, some several times. No Boer
prisoner of war—that is, captured in action—was released. In
December, 1900, we had about 15,000 in our possession; in May,
1902, about 50,000.
It was mainly by this attrition of the Boer forces that we reduced
them to submission. The element of historical truth in Sir John
French's proposition is this: that in 1900, after the fall of
Bloemfontein, a considerable number of Boers surrendered
voluntarily, not in action, and were dismissed to their farms under a
pledge not to fight again—a pledge which they broke, under
circumstances into which we need not enter. There are no exact
statistics as to the numbers of these men, but at an outside estimate
they cannot have amounted to more than 5 per cent. of the total
number of Boers engaged in the war. In any case, the point is totally
irrelevant to the question of shock-tactics. That is a question of
combat, and in combat, as Sir John French is aware, the Boers were,
nine times out of ten, greatly outnumbered.
Such are Sir John French's reasons for the failure of the lance and
sword in South Africa. They constitute an instructive revelation of
the mental attitude of the advocates of those weapons. Is it not
plain that we are dealing here with a matter of faith, not of reason;
of dogma, not of argument; of sentiment, not of technical practice?
The simple technical issue—what happens in combat?—is
persistently evaded, and refuge sought in vague and inaccurate
generalizations, which, when tested, turn out to throw no light upon
the controversy.
Sir John French himself manages to demonstrate in this same
Introduction that the question is really one of sentiment. It is a
seemingly incurable delusion with him that the whole campaign on
behalf of the rifle is an attack of a personal nature on the war
exploits of himself and the regular Cavalry, instead of being, what it
really is, an attack on the lances and swords carried by the Cavalry.
This delusion carries him to the strangest lengths of professional
egotism. In the whole of this Introduction there is not a line to
indicate that any British mounted rifleman unprovided with steel
weapons took part in the war, or that the tactics and conduct of
these men have the smallest interest for Englishmen or the smallest
bearing on the present controversy. No one would gather that our
Colonial mounted riflemen led the way in tactical development, and
frequently, brief and rough as their training had been, excelled the
Cavalry in efficiency, simply because they were trained on the right
principles with the right weapon.
"Even in South Africa," says Sir John French, "grave though the
disadvantages were under which our Cavalry laboured from short
commons and overwork" [as though these disadvantages were not
shared equally by our mounted riflemen and by the Boers
themselves!], "the Boer mounted riflemen acknowledged on many
occasions the moral force of the cold steel, and gave way before it."
Then follows a concrete instance, taken from the action of Zand
River in May, 1900.
Anyone familiar with the history of the war must have felt deep
bewilderment at the General's choice, for purposes of illustration, of
this action, which has not generally been held to have reflected high
credit on the Cavalry.
It is needless to discuss the battle in detail, because the accounts of
it are set forth clearly and accurately enough in the "Official" and
Times Histories, and, inter alia, in Mr. Goldman's work, "With French
in South Africa." As a very small and unimportant episode in the
battle, there was certainly a charge by a whole brigade of regular
Cavalry against some Boers whom the Times History describes as a
"party," and whom Mr. Goldman, who was present, estimates at 200
in number; but it is perfectly clear, from all accounts, (1) that the
casualties resulting from the charge were too few to deserve record;
(2) that the charge had no appreciable effect upon the fortunes of
the day; (3) that the Cavalry on the flank in question suffered
serious checks and losses at the hands of a greatly inferior force;
and (4) that Sir John French's turning force, like General
Broadwood's turning force on the opposite flank, completely failed to
perform the supremely important intercepting mission entrusted to
them by Lord Roberts, and failed through weakness in mobile fire-
action.
Sir John French's version of the action teems with inaccuracies. All
the cardinal facts, undisputed facts to be found in any history, upon
which the judgment of the reader as to the efficacy of the steel must
depend, are omitted. There are no figures of relative numbers, no
times, no description of the terrain, no statement of casualties. I will
instance only one, but the greatest, error of fact. He writes that "the
rôle of the Cavalry division was to bring pressure to bear on the right
flank of the Boer army, in order to enable Lord Roberts to advance
across the river and attack the main Boer forces."
This is a highly misleading account of Roberts's tactical scheme for
the battle. Eight thousand Boers, disposed in a chain of scattered
detachments, held no less than twenty-five miles of country along
the north bank of the Zand River, their right resting on the railway,
which ran at right angles to the river. We had 38,000 men, including
12,000 mounted men, of whom 5,000 were regular Cavalry. To have
used the mounted Arm merely to "bring pressure to bear" upon the
Boer flanks would have been a course altogether unworthy of Lord
Roberts and the great army he controlled. He set no such limited
aim before the Cavalry. He planned to surround and destroy the
enemy by enveloping movements on both flanks, and gave explicit
orders to that effect. French, with 4,000 men, had orders to ride
round the Boer right flank, and seize the railway in their rear at
Ventersburg Road. The same objective was given to the turning
force under Broadwood, 3,000 strong, on the Boer left. Both
enveloping operations failed. To "press" the Boers into retreat was
nothing. They must have retreated anyhow, in the face of an army
five times their superior. The point was to prevent them from
retreating into safety, to cut off their retreat, and with mounted
turning forces together nearly equal to the whole Boer force this aim
was perfectly feasible, given one condition, which was not fulfilled—
that our mounted troops, headed by our premier and professional
mounted troops, the Cavalry, could use their rifles and horses
approximately as well as the Boers.
Now let us come to the heart of the matter.
Let us waive all criticism of the accuracy and completeness of Sir
John French's narrative, and test the grounds of his belief that it was
owing to their fear of the sword that the Boers gave way when
Dickson's brigade charged. The Cavalry carried firearms as well as
swords, and outnumbered the party charged by at least five to one.
We cannot apply the test of casualties, because there were so few.
The only test we can apply is that of analogy from other combats.
Conditions similar to those of Zand River were repeated, on a
smaller or larger scale, thousands of times. Do we find that steel-
armed mounted troops had greater moral effect upon the enemy
than troops armed only with the rifle? Did the presence of the lance
and sword on the field of combat make any difference to the result?
The answer, of course, is that it made no difference at all. Anyone
can decide this question himself. We know precisely what troops
were present, and how they were armed, in all the combats of the
war.
We can detect many different factors at work, psychological,
technical, tactical, topographical; but there is one factor which we
can eliminate as wholly negligible, and that is the presence of the
lance and sword. The same phenomena reappear whether those
weapons are there or not. For example, during Buller's campaign for
the conquest of Northern Natal (May to June, 1900) very little use
was made of regular Cavalry. During the first phase, the advance
over the Biggarsberg, the six regiments of Cavalry at Buller's
disposal were left behind at Ladysmith. The mounted work
throughout was done mainly by irregulars. Was it of a less
aggressive and vigorous character on that account, by analogy, say,
with the mounted operations during the advance of Roberts from
Bloemfontein to Pretoria? We find, on the contrary, that the results
were better. The total relative numbers on the Boer side and our side
were about the same: we were about four to one. But while Roberts
had 12,000 mounted men, of whom 5,000 were Cavalry, Buller had
only 5,500 mounted men, of whom 2,500 were Cavalry. Do we find
that when the steelless irregulars mounted their horses, as Dickson's
brigade mounted their horses, and made a rapid aggressive advance
—"charged," that is—the Boers were any less inclined to retreat? On
the contrary, they were more inclined to do so. Witness, for instance,
Dundonald's long and vigorous pursuit with his irregular brigade over
the Biggarsberg on May 14.
Or take the Bloemfontein-Pretoria advance, in which Zand River itself
was an incident. Can we trace any further this alleged "terror of the
cold steel"? Allowance must be made for the brief and inadequate
training of the Mounted Infantry and Colonials; but, even with this
allowance, a study of the facts shows that they did as well as the
Cavalry, and sometimes better. The only effective local pursuit was
made by Hutton's Australians at Klipfontein (May 30), where a gun
was captured. These men had no steel weapons, yet they charged,
and rode down their enemy.
Take Plumer's brilliant defence of Rhodesia with mounted riflemen.
Take the relief of Mafeking, one of the most arduous and finely-
executed undertakings of the war. Did the 900 troopers of the
Imperial Light Horse who carried it out suffer from the lack of
swords and lances? They would not have taken them at a gift. Did
their work compare unfavourably with that of the Cavalry Division,
6,000 strong, in the relief of Kimberley? On the contrary, when we
contrast the numbers employed, the opposition met with and the
distance covered (251 miles in eighteen days), we shall conclude
that the achievement of the irregulars was by far the more
admirable of the two.
An infinity of illustrations might be cited to prove the same point,
but, in truth, it is a point which stands in no need of detailed proof.
The onus probandi lies on those who defend weapons which
palpably failed. It is the Cavalryman's fixed idea that "mounted
action," as the phrase goes, is associated solely with steel weapons;
that soldiers in the saddle are only formidable because they carry
those weapons. Mounted riflemen are pictured as dismounted,
stationary, or as employing their horses only for purposes of flight.
These fictions were blown to pieces by the South African War, and
the irony of the case is that Sir John French gratuitously brings
ridicule on the Cavalry by reviving them. If they are not fictions, the
Cavalry stand condemned by their own pitifully trivial record of work
done with the steel. But this is to slander the Cavalry. They do not
stand condemned; their steel weapons stand condemned. They
themselves, like all other mounted troops, did well precisely in
proportion to their skill in and reliance on the rifle and horse
combined. Their lances were soon returned to store; their swords,
after rusting in the scabbards for another year, were also, in the case
of nearly all regiments, abandoned; a good Infantry rifle replaced
the weak carbine, and the Cavalry became definitely recognized as
mounted riflemen.
No one has ever regarded Sir John French himself as otherwise than
a leader of conspicuous energy and resource. But, so far from owing
anything to the lance and sword, he suffered heavily from the almost
exclusive education of his troops to those weapons, and from the
inadequacy of their firearm.
CHAPTER III
THE BRITISH THEORY OF THE ARME BLANCHE
And now, what in Great Britain is the real theory on this question?
Let us go to Sir John French again. The South African War, he says,
is no guide for the future. It is abnormal, for the reasons stated
above. The Manchurian War he has also stated to be abnormal.
Where, then, is the theoretical advantage of the lance and sword
over the modern rifle? We are left in ignorance. The physical
problem is untouched. All we have is the bare dogmatic assertion
that the steel weapon can impose tactics on the rifle. This is how Sir
John French expresses the theory on p. xi of his Introduction: "Were
we to do so" (i.e., to "throw our cold steel away as useless lumber"),
"we should invert the rôle of Cavalry, turn it into a defensive arm,
and make it a prey to the first foreign Cavalry that it meets; for good
Cavalry can always compel a dismounted force of mounted riflemen
to mount and ride away, and when such riflemen are caught on their
horses, they have power neither of offence nor defence, and are
lost."
Eight years have elapsed since the Boer War. Memories are short,
and it is possible now to print a statement of this sort, which, if
promulgated during the dust and heat of the war itself, when the
lance and sword fell into complete and well-merited oblivion, and
when mounted men on both sides were judged rigidly by their
proficiency in the use of the horse and the rifle, would have excited
universal derision. The words which follow recall one of the writer's
"abnormalities" already commented on: "If in European warfare such
mounted riflemen were to separate and scatter, the enemy would be
well pleased, for he could then reconnoitre and report every
movement, and make his plans in all security. In South Africa the
mounted riflemen were the hostile army itself, and when they had
dispersed there was nothing left to reconnoitre; but when will these
conditions recur?" When, indeed? There was nothing, it seems, to
reconnoitre, because the enemy always "scattered and dispersed."
And the Generals were "well pleased"! "Nothing left to reconnoitre"!
One can only marvel at the courage of Sir John French in breathing
the word "reconnoitre" in connection with Cavalry work in South
Africa.
He ought to admit that Cavalry reconnaissance was bad, and that
the army suffered for it. No historian has ever defended it. It was
the despair of Generals who wanted information as to the position of
the enemy. Wits apart, the rifle ruled reconnaissance, as it obviously
always must rule it. Ceteris paribus, the best rifleman is the best
scout. The Cavalry were not good riflemen, and were therefore not
good scouts. Not a single Boer scout from the beginning to the end
of the war was hurt by a sword or lance. Those weapons were a
laughing-stock to foe and friend alike. And Sir John French's
proposition is, not so much that the reconnaissance was good—
presumably, that goes without saying—but that there was nothing to
reconnoitre, thanks, apparently, to the terror spread by the lance
and sword.
Such a travesty of the war may be left to speak for itself. But it is
very important to comprehend the root idea which underlies it, an
idea which, as we shall see, reappears in a less extreme form in
General von Bernhardi's writings. It is expressed in the words "we
should invert the rôle of Cavalry, turn it into a defensive arm." The
rifle, it will be seen, is regarded as a defensive weapon, in
contradistinction to the lance and sword, which are offensive
weapons. To sustain this theory, it is absolutely necessary, of course,
to proceed to the lengths to which Sir John French proceeds—to
declare, in effect, that there was no war and no fighting; for if once
we concede that there was a war, study its combats and compute
their statistical results, we are forced to the conclusion that the rifle
must have been used in offence as well as in defence. Abstract
reflection might well anticipate this conclusion by suggesting that a
defensive weapon and a defensive class of soldiers are
contradictions in terms.
There must be two parties to every combat, and, unless there is
perfect equilibrium in combat, one side or the other must definitely
be playing an offensive rôle; and, even in equilibrium, both sides
may be said to be as much in offence as in defence, whatever
weapons they are using. The facts mainly illustrate the abstract
principle. The Boers could not have taken guns and prisoners while
acting on the defensive. Talana Hill, Nicholson's Nek, Spion Kop,
Stormberg, Sannah's Post, Nooitgedacht, Zilikat's Nek, Bakenlaagte,
were not defensive operations from the Boer point of view. Nor were
Magersfontein, Colenso, Elandslaagte, Paardeberg defensive
operations from the British point of view. Whether the rifles were in
the hands of Infantry or mounted troops is immaterial. A rifle is a
rifle, whoever holds it. It is just as absurd to say that the Boers who
rode to and stormed on foot Helvetia and Dewetsdorp belonged to a
defensive class of soldiers as it is to say that the Infantry who
walked to and stormed Pieter's Hill belonged to a defensive class of
soldiers. It is still more absurd to say that the Boers who charged
home mounted at Sannah's Post, Vlakfontein, Bakenlaagte,
Roodewal, Blood River Poort, and many other actions, and the
British mounted riflemen who did similar things at Bothaville, were
performing a defensive function, while the Cavalry who pursued at
Elandslaagte were performing an offensive function. Take this action
of Elandslaagte, the solitary genuine example of a successful charge
with the arme blanche. By whom was the real offensive work done?
By the Infantry and by the Imperial Light Horse acting dismounted,
and by the Artillery. After hours of hard and bloody fighting, these
men stormed the ridge and forced the Boers to retreat. In the act of
retreat they were charged by the Cavalry, who had hitherto been
spectators of the action.
It might be objected that I am taking a verbal advantage of Sir John
French. He is guilty, it may be argued, only of the lesser fallacy—that
of thinking that the rifle is a defensive weapon for mounted men as
distinguished from Infantry. Not so. He perceives the logical peril of
admitting that the rifle is an offensive weapon for any troops, and in
another passage, when deprecating attacks on the "Cavalry spirit"
(p. vii), makes use of the following words: "Were we to seek to
endow Cavalry with the tenacity and stiffness of Infantry, or take
from the mounted arm the mobility and the cult of the offensive
which are the breath of its life, we should ruin not only the Cavalry,
but the Army besides." (The italics are mine.) It may be pointed out
that, but for their firearms and the mobility and offensive power
derived from them, the Cavalry in South Africa would indeed have
been "ruined" beyond hope of rehabilitation.
But let us look at the underlying principle expressed. Infantry are
"stiff and tenacious" (that is, obviously, in defence). Cavalry have the
"cult of the offensive." Those are the distinctive "spirits" of the two
Arms. The bitter irony of it! Which Arm really displayed the most
"offensive spirit" in South Africa? Study the lists of comparative
casualties in the two Arms during that period of the war in which
Infantry were mainly engaged. If at Talana, the Battle of Ladysmith,
Colenso, Dronfield, Poplar Grove, Karee Siding, Sannah's Post, Zand
River, Doornkop, or Diamond Hill, the Cavalry in their own sphere of
work had shown the offensive power displayed by the Infantry in the
battles on the Tugela, or in Methuen's campaign from Orange River
to Magersfontein, or at Driefontein, Doornkop, Bergendal, and
Diamond Hill, the war would have showed different results. There
was no distinction in point of bravery between any branches of the
Services. Fire-power and fire-efficiency were the tests, and lack of a
good firearm and of fire-efficiency on only too many occasions fatally
weakened the offensive spirit of the Cavalry.
And what of the "tenacity and stiffness" with which we must not
"seek to endow" Cavalry? Ominous words, redolent of disaster! Have
not they fully as much need of those qualities as Infantry? Imagine
our Cavalry doing the work that the Boers had to do on so many
score of occasions—to fight delaying rearguard actions against
immensely superior numbers, with no reserves, and a heavy convoy
to protect. We shall be fortunate if, through reliance on and skill in
the use of the rifle, they display as much tenacity and stiffness as
Botha's men at Pieter's Hill or Koch's men at Elandslaagte against
forces four times their superior in strength, to say nothing of such
incidents as Dronfield, where 150 Boers defied a whole division of
Cavalry and several batteries; of Poplar Grove and Zand River, where
small hostile groups virtually paralyzed whole brigades; or of
Bergendal, where seventy-four men held up a whole army. There
was nothing abnormal tactically or topographically about any of
these incidents. Any function performed by the Boer mounted
riflemen may be demanded from our Cavalry in any future war.
Suppose them, for example, vested with the strictly normal duty of
covering a retreat against a superior force of all arms; suppose a
squadron, like the seventy-four Zarps at Bergendal, ordered to hold
the cardinal hill of an extended position, and their leader replying:
"This is not our business. We are an offensive Arm. We cannot
entrench, and we have not the tenacity and stiffness of Infantry. Our
business is to charge with the lance and sword." Would the General
be well pleased?
The reader will ask for the key to this curious discrimination between
the "spirits" of Cavalry and Infantry. It is this: The lance and sword,
when pitted against the rifle, can, if they are used at all, only be
used in offence. Men sitting on horseback, using steel weapons with
a range of a couple of yards, plainly cannot defend themselves
against riflemen. Even the Cavalry tacitly admit this principle, and if
they accepted its logical consequence, a logical consequence
completely confirmed by the facts of modern war, they would admit,
too, that the sword and lance cannot be used for offence against
riflemen in modern war. But they will not admit that. "Tant pis pour
les faits," they say. "All modern war is abnormal. Our steel weapons
dominate combat. Without them we are nothing."
In these circumstances they are forced to set up this strange theory
—that Cavalry is a peculiarly "offensive" Arm, a theory which the
reader will find expressed in all Cavalry writings. On the face of it the
theory is meaningless. It is a mere verbal juggle, because, as I said
before, there are two parties to every combat, and defence is the
necessary and invariable counterpart of offence. All combatant
soldiers, including Cavalry, carry firearms, and if Cavalry choose to
use these firearms in offence, by hypothesis they will impose fire-
action on the defence, whether the defence consists of Cavalry or
any other class of troops. Conversely, if they use their rifles in
defence, as by hypothesis they must, they will impose fire-action on
the attacking force, be it Cavalry or any other Arm. In other words,
the rifle governs combat. That is why the lance and sword
disappeared in South Africa. Both in offence and defence the Boer
riflemen forced the Cavalry to accept combat on terms of fire.
And what kind of Cavalry do our Cavalrymen count upon meeting in
our next war? They count, incredible as it seems, upon meeting
Cavalry not superior, but inferior, to the Boer mounted riflemen,
inferior because, as I shall show from von Bernhardi, they defy
science, shut their eyes to the great principle of the supremacy of
fire, are prepared deliberately to abdicate their fire-power, and hope
to engage, by mutual agreement, as it were, and on the
understanding that suitable areas of level ground can be found, in
contests of crude bodily weight.
And what of the action of Cavalry against other Arms? We know Sir
John French's opinion about mounted riflemen. They will gallop for
their lives "defenceless" at the approach of "good" Cavalry. But
Infantry, riflemen without horses, who cannot gallop, but can only
run? Their case, it would seem, must be still more desperate. They
are not only defenceless, but destitute even of the means of flight.
And yet even Sir John French credits them, if not with an offensive
spirit, at least with "tenacity and stiffness," derived, of course, from
their rifles. But their mounted comrades, armed with these same
rifles, lack these soldierly qualities. We arrive thus at the conclusion
that the horse, which one would naturally suppose to be a source of
immensely enhanced mobility and power, is a positive source of
danger to a rifleman unless he also carries a lance or sword.
Here is the reductio ad absurdum of the arme blanche theory, and I
beg for the reader's particular attention to it. Of course, the
conclusion is in reality too absurd; for Sir John French himself does
not really believe that Infantry are a defensive Arm. In point of fact,
no serious man believes that Infantry in modern war have anything
whatever to fear from the lance and sword, and their training-book
is written on that assumption. Nor does Sir John French really
believe that Mounted Infantry are a defensive Arm who run from
Cavalry; otherwise, he would never rest until he had secured the
complete abolition of our Mounted Infantry, who are now, under his
official sanction, designed to act, not only as divisional mounted
troops against steel-armed Continental Cavalry, but to co-operate
with, and in certain events take the place of, our own regular Cavalry
in far wider functions, and are presumably not going to be whipped
off the field at the distant glimpse of a lance or sword. And I may
say here that the reader can obtain no better and more searching
sidelight on the steel theory than by studying the Mounted Infantry
Manual (1909) for the rules given about similar and analogous
functions. Nor, if Sir John French went the whole length of the
theory, would he, as Inspector-General, have permitted our Colonial
mounted riflemen to think that they might be of some Imperial value
in a future war. It is only in order to sustain his a priori case for the
steel weapons that he finds himself forced into the logical impasses
to which I have drawn attention.
There is one further point to deal with before leaving Sir John
French's Introduction. He admits the necessity of a rifle for Cavalry,
and we may presume him to admit that the Boer War proved the
necessity for a good rifle and the futility of a bad carbine. When, in
his opinion, is this rifle to be used? "I have endeavoured to impress
upon all ranks," he writes on page xvii, "that when the enemy's
Cavalry is overthrown, our Cavalry will find more opportunities of
using the rifle than the cold steel, and that dismounted attacks will
be more frequent than charges with the arme blanche. By no means
do I rule out as impossible, or even unlikely, attacks by great bodies
of mounted men against other arms on the battle-field; but I believe
that such opportunities will occur comparatively rarely, and that
undue prominence should not be given to them in our peace
training." (The italics are mine.)
This is a typically nebulous statement of the combat functions of
Cavalry in modern war, and, like the generality of such statements,
will be found to contain, if analyzed, a refutation of the writer's own
views on the importance of the arme blanche. We ask ourselves
immediately why he thought it necessary to account for the failure of
the arme blanche in South Africa by the elaborate accumulation of
arguments for "abnormality" developed a few pages earlier. After all,
it seems, the war, in its bearing upon the efficacy of weapons, was
normal. The Boers had no "Cavalry" in the writer's use of the word—
that is, steel-armed Cavalry. What he assumes to be the primary and
most formidable objective of our own steel-armed cavalry was,
therefore, by a fortunate accident, non-existent. There was no need
to "overthrow" it, because there was nothing to overthrow, and our
Cavalry was free from the outset to devote its attention to the "other
Arms"—that is, to riflemen and Artillery—assumed evidently by the
writer to be a secondary and less formidable objective. But here,
apparently, "opportunities" for the arme blanche are to occur
"comparatively rarely" in any war, European or otherwise, whether
the riflemen show "tenacity and stiffness" or "disperse for hundreds
of miles"; whether the horses are perennially fresh or perennially
fatigued; whether we outnumber the foe or they outnumber us;
whether annexation or mere victory is our aim.
If only, we cannot help exclaiming, this principle had been
recognized in 1899! We knew the Boers had no swords or lances: we
had always known it. If only we had prepared our Cavalry for the
long-foreseen occasion, trained them to fire, given them good
firearms, and impressed upon them that opportunities for shock
would occur "comparatively rarely," instead of teaching them up to
the last minute that fire-action was an abnormal, defensive function
of their Arm, worthy of little more space in their Manual than that
devoted to "Funerals," and much less than that devoted to
"Ceremonial Escorts."
The root of the fallacy propounded by Sir John French lies in his
refusal to recognize that a rifle may be just as deadly a weapon in
the hands of Cavalry as in the hands of "other Arms," and, indeed, a
far more deadly weapon, thanks to the mobility conferred by the
horse. If, for example, Infantry can, as he tacitly admits they can,
force Cavalry to adopt fire-action, a fortiori can Cavalry, if they
choose, force Cavalry to adopt fire-action. In other words, the rifle
governs combat, as it did, in fact, govern combat in South Africa and
Manchuria. But Cavalry operating against Cavalry, according to Sir
John French, are not so to choose. We can only speculate upon what
may happen if one side is so unsportsmanlike as to break the rules
and masquerade as another Arm. The stratagem is simple, because
the rifle kills at a mile, and the orthodox Cavalry may be unaware
until it is too late that the unorthodox Cavalry is playing them a trick.
Meanwhile the best riflemen, whether they have horses or not, will
win, and horsemen who have spent 80 or 90 per cent. of their time
in steel-training will have cause to regret their error.
But Sir John French contemplates no such awkward contingencies.
We may surmise, however, that it is owing to an uncomfortable
suspicion of his own fallacy that in this paragraph and elsewhere he
is so careful to isolate inter-cavalry combats from mixed combats,
and to postulate the complete "overthrow" of one Cavalry—an
overthrow effected solely by the arme blanche—before permitting
the surviving Cavalry, in Kipling's words, to "scuffle mid unseemly
smoke." He has a formula for the occasion. In this paragraph it is
"when the enemy's Cavalry is overthrown." On page xiv, speaking of
raids, which he deprecates, he says: "Every plan should be
subordinate to what I consider a primary necessity—the absolute
and complete overthrow of the hostile Cavalry"; and on page xv: "If
the enemy's Cavalry has been overthrown, the rôle of
reconnaissance will have been rendered easier," a truism upon which
the Boer War throws a painfully ironical sidelight.
If the reader is puzzled by this curiously superfluous insistence on
the "overthrow" of the enemy analogous to the equally superfluous
insistence on the "offensive" character of the Cavalry Arm, he will
once more find an explanation in the anomalous status of the arme
blanche. No one would dream of repeatedly impressing upon
Infantry, for example, as though it were a principle they might
otherwise overlook, that their primary aim must be the absolute and
complete overthrow of the hostile Infantry. But the advocate of the
arme blanche is always on the horns of a dilemma. He dare not
admit that the rifle in the hands of Cavalry is as formidable a
weapon as in the hands of Infantry, if not a far more formidable
weapon. He therefore instinctively tends to picture steel-armed
Cavalry as perpetually pitted against steel-armed Cavalry. Both sides
are always in offence until the moment when one is "completely and
absolutely overthrown." Then some other rôles, very vaguely
delineated, open up to the victor. Needless to say, this picture bears
no resemblance to war. Troops are not, by mutual agreement, sorted
out into classes, like competitors in athletic sports. Every Arm must
be prepared to meet at any moment any other Arm, and any other
weapon.
Nor do these "complete and absolute" obliterations of one Arm by its
corresponding Arm ever, in fact, happen. That they could ever
happen through the agency of the lance and sword is the wildest
supposition of all. Compared with rifles, these weapons are
harmless. Even the most backward and ignorant Cavalry, trained to
rely absolutely on the lance and sword, would, if it found itself
beaten in trials of shock, or, like the Japanese Cavalry, greatly
outnumbered, resort to the despised firearm, imitate the tactics and
vest itself with something of the "tenacity and stiffness," as well as
with the aggressive potency, of those "other Arms," which, by
hypothesis, must be attacked with the rifle; and in doing so it would
force its antagonist to do the same.

CHAPTER IV
CAVALRY IN COMBAT
I. Instruction from History.
I have gone at considerable length into the opinions of Sir John
French, as expressed in his Introduction to von Bernhardi's work—
partly because it is more important for us to know what our own
Cavalrymen think than what German Cavalrymen think, and partly
because it will be easier for the reader to estimate the value of the
German writer's views if he is already familiar with Sir John French's
way of thinking. We should expect, of course, to find identity
between the views of the two men, since Sir John French acclaims
the German author as the fountain of all wisdom; but on that point
the reader would be well advised to reserve judgment.
I shall now discuss "Cavalry in War and Peace," and first let me say
a few more words on a very important point—the circumstances of
its composition.
When General von Bernhardi wrote his first book, "Cavalry in Future
Wars," he did not take the current German Cavalry Regulations as
his text, because they were too archaic to deserve such treatment.
He condemned them in the mass, and, independently of them,
penned his own scheme for a renovated modern Cavalry. After about
nine years of complete neglect, during which the two great wars in
South Africa and Manchuria were fought, the German authorities
decided that some recognition of modern conditions must be made.
They have recently re-armed the Cavalry with a good carbine, and
issued a new book of Cavalry Regulations. These circumstances
induced the General to write his second book, "Cavalry in War and
Peace," and to throw it into the form of a direct criticism of the
official Regulations, which he constantly quotes in footnotes and
uses in the text of his own observations and constructive
recommendations.
What is the result? The first point to notice is that he regards the
new official Regulations, "though better than the old ones," as
thoroughly and radically bad. His writings, he says, "have fallen on
barren soil." He condemns them almost invariably for precisely the
same reason as before, namely, that they virtually ignore the rifle in
practice, and continue the ancient and worn-out traditions of the
steel, with mere lip-service to the modern scientific weapon. But a
disappointment was in store for those who had hoped that the
mental process involved in criticizing concrete Regulations, as well as
the vast mass of instructive phenomena presented by the two wars
which, when he wrote first, were still "future wars" to him, would
arouse the General himself to a realization of the inconsistencies in
his own earlier work.
These hopes have been falsified. The fascination of the arme
blanche was proof against the test, and the result is one of the
strangest military works which was ever published. Bitter satire as it
is on the official system of training, any impartial reader must end by
sympathizing, not with the satirist, but with the officials satirized.
They at any rate try to be logical. Their concessions to fire are the
thinnest pretence; their belief in shock undisguised and sincere.
Whatever follies and errors this belief involves them in, they pursue
their course with unflinching consistency, sublimely careless of
science and modern war conditions.
Their critic, on the other hand, keenly alive to the absurdities
inculcated, has not the mental courage to insist on the only logical
alternatives. Faced with the necessity of proving their absurdity, he
refuses to use the only effective weapon available, gives away his
own case for fire by weak concession to shock, and succeeds in
producing a work which will convince no one in Germany, and the
greater part of which, as a practical guide to Cavalrymen, in this
country or any other, is worthless. A mist of ambiguity shrouds what
should be the simplest propositions. We move through a fog of ill-
defined terms and vague qualifications. We puzzle our brains with
academical distinctions, and if we come upon what seems to be
some definite recommendation, we are pretty sure to find it stultified
in another chapter, or even in the same chapter, by a reservation in
the opposite sense. The key to each particular muddle, to each
ambiguity, to each timid qualification, to each confusing doctrinaire
classification, is always the same—namely, that the writer, from
sheer lack of knowledge of what modern fire-tactics are, at the last
moment shrinks from his own theories about their value. What has
happened is exactly what one would expect to happen. In Germany
the General admits his failure, and in England he is hailed by Sir
John French, who politely ignores his blunders about fire-action, as
the apostle of the steel, instead of what he really is, the apostle,
though the ineffectual apostle, of the rifle.
Let us first be quite clear as to his opinion of the present German
Cavalry. "While all other Arms have adapted themselves to modern
conditions, Cavalry has stood still," he says on the first page of his
Introduction. They have "no sort of tradition" for a future war (p. 5).
Their training creates "no sound foundation for preparation for war."
It is "left far behind in the march of military progress." "It cannot
stand the test of serious war." It is trammelled by the "fetters of the
past," and lives on "antiquated assumptions" (p. 6). Its "mischievous
delusions" will result in "bitter disappointment" (p. 175). Many of the
new Regulations "betoken failure to adapt existing principles to
modern ideas" (p. 361); others "do not take the conditions of reality
into account"; or "cannot be regarded as practical"; or are
"provisional"; and of one set of peculiarly ludicrous evolutions he
uses the delightful phrase that they are "included in the Regulations
with a view to their theoretical and not for their practical
advantages" (p. 333). He stigmatizes "the formal encounters," the
"old-fashioned knightly combats," the "pro forma evolutions," the
"survivals of the Dark Ages," the "spectacular battle-pieces," the
"red-tape methods," the "tactical orgies," the "childish exercises,"
and "set pieces" of peace manœuvres. The origin of the trouble, he
says, is "indolent conservatism" (p. 366). "Development in our
branch of the Service has come to a standstill" (ibid.). The officers
do not study history or the progress of foreign Cavalries. And he
reiterates again and again his general conclusion that the Cavalry is
unprepared for war.
Such is the material which forms his text. And we may ask at once,
is a book based on such an appalling state of affairs, and addressed
exclusively to a Cavalry described as being given over to ancient
shibboleths, mischievous delusions and antiquated assumptions—is
such a book likely to deserve the effusive and unqualified praise of
our own foremost Cavalry authority? Is it likely to be worthy of
becoming the Bible of a modern and progressive Cavalry, such as Sir
John French considers our own Cavalry, trained under his own
guidance, to be? Is it likely to be "exhaustive," "convincing,"
"complete"?
To suppose so is to insult the intelligence of our countrymen. We do
not teach the ABC in our Universities. Our natural science schools do
not assume that their pupils belong to the "Dark Ages," and waste
two-thirds of their energy in laborious refutations of such extinct
superstitions as witchcraft. The education of our sailors to modern
naval war is not conducted on the assumption that the Navy consists
of wooden sailing-vessels whose inadequacy to modern conditions
must be elaborately demonstrated. A gunnery course—and the
reader will note the analogy—does not consist mainly of arguments
designed to prove that the cutlass is no longer so important a
weapon as the long-range gun and the torpedo. Nor—in the military
sphere—are our Infantry and Artillery instructed with a view to
weaning them from the cult of the pike and the catapult.
So, too, we may be quite sure that there is something radically
wrong when our Cavalry, in their search for an authoritative
exposition of modern Cavalry tactics, are reduced to relying on a
foreign writer who writes for a Cavalry ignorant of the elements of
modern Cavalry tactics, and a good half of whose work is taken up
with scoldings and appeals which from our British point of view are
grotesquely redundant. All that is good in what von Bernhardi says
about fire-action we know from our own war experience. All his
errors about fire-action we can detect also from our own war
experience.
We should expect Sir John French to comment on these facts, to
warn his readers that the book under review was written for a
Cavalry unversed in modern war and blind to its teaching. We should
expect some note of pride and satisfaction in the fact that his own
national Cavalry did not need these scathing and humiliating
reminders that war is not a "theoretical" and "childish" pastime, but
a serious and dangerous business; some hint to the effect that
perhaps we, with our three years' experience of the modern rifle,
may have something useful to tell General von Bernhardi about
principles which he has framed in the speculative seclusion of his
study. Not a word, not a hint of any such warning or criticism. The
topic is too dangerous. Once admit that South Africa counts—to say
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy