Sie sind auf Seite 1von 14

COMPUTER PROGRAMMING

Engr. Anees Ahmed Soomro


Assistant Professor
CSE QUEST Nawabshah
INTRODUCTION TO COMPUTER PROGRAMMING

1) String functions
2) Btrees
3) Stack, Queue
4) ctype.h
String functions
String I/O Functions
• There are special functions designed specifically for String
I/O.
• gets(string_name);
• puts(string_name);
• Gets function reads in a String from keyboard. When the
user hits a carriage return the string is inputted.
• The carriage return is not part of string and end of string
character is automatically appended.
• The function puts displays a string on monitor
Example
char phrase[100];
printf(“enter a sentence”);
gets(phrase);
puts(phrase);

• Included in String.h are several more String related


function that are free for you to use.
strcat Appends to a String
strchr Finds first occurrence of a given character
strcmp Compares two strings
strcmpi Compares two, String, non-case sensitive
strcpy Copies one string to another
strlen Finds length of string
strncat Appends n characters of String
String functions continued
strncmp compares n characters of two strings
strncpy copies n characters of two strings
strnset sets n characters of string to a given character
strrchr Finds last occurrence of given character in string
strspn Finds first substring from given character set in
string.
Trees Examples
 Unix / Windows file structure
Definition of Tree

A tree is a finite set of one or more nodes


such that:
There is a specially designated node called
the root.
The remaining nodes are partitioned into n>=0
disjoint sets T1, ..., Tn, where each of these sets is
a tree.
We call T1, ..., Tn the subtrees of the root.
Level and Depth

Level
node (13)
degree of a node 1
3 A 1
leaf (terminal)
nonterminal 2
parent
children 2
B 2 1 C 2 3 D 2 3
sibling
2 E 3 0 F 3 0 G 31 H 3 0 I 3 0 J
degree of a tree (3) 4
3
ancestor
level of a node
height of a tree (4) 0 K 4 0 L 4 0M 4
Terminology

The degree of a node is the number of subtrees


of the node
The degree of A is 3; the degree of C is 1.
The node with degree 0 is a leaf or terminal
node.
A node that has subtrees is the parent of the
roots of the subtrees.
The roots of these subtrees are the children of
the node.
Children of the same parent are siblings.
The ancestors of a node are all the nodes
along the path from the root to the node.
Btrees
• M-way search trees have the advantage of minimizing file accesses
due to their restricted height.
• However it is essential that the height of the tree be kept as low as
possible and therefore these arises the need to maintain balanced
m-way search trees, such a balanced m-way search tree is what is
defined as a B tree.
Definition
• A Btree of order m, if non-empty, is an m-way search tree in which:
i. The root has atleast two child nodes and at most m child nodes.
ii. The internal nodes except the root have at least[m/2] child nodes
and at most m child nodes.
iii. The number of keys in each internal node is less than the number
of child nodes in a manner similar to that of m-way search trees.
iv. All leaf nodes are on same level
Stacks
• A stack is a list of elements in which an element may be inserted or
deleted only at one end, called top of stack.
• This means, in particular, that elements are removed from stack in
reverse order of that in which then were inserted into the stack.
• Special terminology is used for two basic operators
(a) “PUSH” is a term used to insert an element into a stack.
(b) “POP” is the term to delet/Remove an element from stack.
Queue
• A queue is a linear list of elements in which deletions can take
place only at one end, called front, and insertion can take place
only at the other end called rear.
• The term “front” and “rear” are used in descending a linear list only
when it is implemented as a queue.
• Queues are also called FIFO lists, since the first element out of
sequence.
• In other words the order in which elements enter a queue is the
order in which they leave contrast with STACK
ctype.h
• There is library of functions to work with character variables.
• The file ctype.h defines additional routines for manipulating characters
isalnum Tests for alphanumeric character
isalpha Tests for alphabetic character
isascii Tests for ASCII character
iscntrl Tests for control character
isdigit Tests for 0-9
isgraph Tests for printable character
islower Tests for lower case character
isprint Tests for printable character
ispunct Tests for punctuation character
isspace Tests for space character
isupper Tests for uppercase character
isxdigit Tests for hexadecimal
toascii Converts character to ASCII code
toascii Converts character to ASCII code
tolower Converts character to lowercase

Das könnte Ihnen auch gefallen