Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Functions for operating on strings are provided with the standard C library; however, we would like to be able to treat strings in our programs as if they were a built-in type. Thus, in this exercise you are to develop a software package in C that implements the STRING Abstract Data Type (ADT). This ADT should at the minimum support the following operations:

 

  1. Retrieve (i, s). Returns element I of string s.
  2. Print(s). Prints the contents of string s.
  3. Concatenate (s1, s2). Concatenates strings s1and s2and returns the resulting string.
  4. Copy (s1, s2). Copies the contents of string s1to string s2.
  5. Compare (s1, s2). Compares string s1 to string s2, returning a result indicating whether s1 is lexicographically greater than s2.
  6. Length (s). Returns the number of characters in the string s.
  7. Capacity (s). Returns the maximum numbers of characters that can be stored in the string s.

 

Proper data encapsulation requires that a structure be created that holds the string representation, as well as information about the string. The following declaration and structure should be placed in a header file called String.h along with the function prototypes for the operations listed above:

 

typedef struct {

char *element;

int length;

int capacity;

} string_type;

/* function prototypes */

string_type Create(char *ary, int capacity);

void Destroy(string_type str);

void Print(string_type str);

string_type Concatenate(string_type str1, string_type str2);

......

 

 

A code fragment that demonstrates how the string package will be used in given below:

 

#include “String.h”

char a[] = “hello”;

char b[] = “hi!”;main()

{

string_type str1, str2;

str1 = Create(a, 15);

str2 = Create(b, 15);

Print(Concatenate(str1, str2));

...... }

Use your string package to perform the following task:

 

Sort the following strings: defunct, abeyance, irrelevant, acquiesce, western, zealous, electric, trihedral, unimodal, vanquish, ambient, abbreviate, edifice, genre, ferrous, breve, brocade. 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education