char first[10]="monkey"; char second[10]="fish"; char* keep;

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16P. 1Winter Quarter Strings Lecture 16.
The simple built-in data types of the C language such as int, float, - are not sufficient to represent complex data such as lists, tables, vectors, and.
Arrays First step is to reserve sufficient space for the array.
Decision Maths 1 Sorting Algorithms Bubble Sort A V Ali : 1.Start at the beginning of the data set. 2.Compare the first two elements,
Pointer Variables The normal variables hold values. For example, int j; j = 2; Then a reference to j in an expression will be identified with the value.
Sort the given string, without using string handling functions.
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Searching and Sorting an Array 4 Searching and sorting are two fundamental algorithms often implemented with arrays –Search an array to determine the location.
Visual C++ Programming: Concepts and Projects
Pointers Ethan Cerami Fundamentals of Computer New York University.
Introduction to C Programming CE
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
Sorting. Algorithms Sorting reorders the elements in an array or list in either ascending or descending order. Sorting reorders the elements in an array.
ECE 103 Engineering Programming Chapter 24 Sorting Herbert G. Mayer, PSU CS Status 6/2/2015 Initial content copied verbatim from ECE 103 material developed.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
CS 162 Intro to Programming II Bubble Sort 1. Compare adjacent elements. If the first is greater than the second, swap them. Do this for each pair of.
Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,
5.3 Sorting Techniques. Sorting Techniques Sorting is the process of putting the data in alphabetical or numerical order using a key field primary key.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Sorting Sorting takes an unordered array and makes it an ordered one
Week 7 Part I Kyle Dewey. Overview Code from last time Array initialization Pointers vs. arrays Structs typedef Bubble sort (if time)
Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Pointers Pointers are variables that contain memory addresses as their values. A variable directly contains a specific value. A pointer contains an address.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Pointers and Classes.
Chapter 9: Sorting and Searching Arrays
CS212: Data Structures and Algorithms
Computer Organization and Design Pointers, Arrays and Strings in C
Data Structures I (CPCS-204)
Arrays.
Command Line Arguments
Alg2_1c Extra Material for Alg2_1
Sorting Algorithms.
Sorting Algorithms: Selection, Insertion and Bubble
CSC 172 DATA STRUCTURES.
Programming Languages and Paradigms
Sorting Data are arranged according to their values.
Basic notes on pointers in C
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
Selection Sort Find the smallest value in the array. Put it in location zero. Find the second smallest value in the array and put it in location 1. Find.
Selection Sort – an array sorting algorithm
C Arrays.
Sorting Given a[0], a[1], ..., a[n-1] reorder entries so that
Chapter 8 Arrays Objectives
Arrays November 8, 2017.
Sorting Data are arranged according to their values.
Arrays Outline Introduction Arrays Declaring Arrays
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
Review of Arrays and Pointers
Straight Selection Sort
Can we solve this problem?
Data Structures (CS212D) Week # 2: Arrays.
Strings and Pointer Arrays
Pointers Pointers are variables that contain memory addresses as their values. A variable name refers to a specific value. A pointer contains an address.
To refer to an element, specify
ECE 103 Engineering Programming Chapter 51 Random Numbers
Chapter 8 Arrays Objectives
Variables, Pointers, and Arrays
Arrays.
Arrays and Pointers CSE 2031 Fall May 2019.
Structures in c By Anand George.
Arrays and Pointers CSE 2031 Fall July 2019.
ㅎㅎ Fourth step for Learning C++ Programming Call by value
Presentation transcript:

char first[10]="monkey"; char second[10]="fish"; char* keep; char* sell; /* keep the monkey sell the fish */ keep = first; /* or &first[0] */ sell = second; printf("Keep the %s\n", keep); printf("Sell the %s\n", sell);

/* Change mind. Keep the fish, sell the monkey. */ /* Swap keep and sell */ char* temp; /* should be up top */ temp = keep; keep = sell; sell = temp; /* No strings have been copied! */ printf("Keep the %s\n", keep); printf("Sell the %s\n", sell);

Sorting some books char books[5][40] = {"Problem Solving in C", "Algorithm Development", "Web Design", "Database Managment", "The C Programming Language"};

/*An array of pointers:*/ char* bookP[5]; /* Have the pointer point to the books */ int i; for (i = 0; i<5; i++) bookP[i]=books[i]; /*The address of the book*/

/*Bubble sort the array, without moving any books! */ /* some variables we will need */ int last; /* subscript of last element of unsorted array*/ int i; /* index of first number in pair being compared */ char* temp;

int n=5; /*number of books */ for (last = n-1; last>=1; last--) for (i=0; i<= last-1; i++) if (strcmp(bookP[i],bookP[i+1])>0) /*swap the pointers*/ { temp=bookP[i]; bookP[i]=bookP[i+1]; bookP[i+1]=temp; }

/* Print out the books in alphabetical order */ for (i=0; i<n; i++) printf("%s \n", bookP[i]); /* Print out the books in stored order */ for (i=0; i<n; i++) printf("%s \n", books[i]);