 Last Lecture Reminder  Array Sorts  Exam Questions Examples  Open Questions ◦ Search Engines ◦ Operating Systems ◦ Multiple Files in Projects  Additional.

Slides:



Advertisements
Similar presentations
Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Advertisements

Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
C Language.
Linked Lists. 2 Merge Sorted Lists Write an algorithm that merges two sorted linked lists The function should return a pointer to a single combined list.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
Sort the given string, without using string handling functions.
Sample Theoretical Question What’s printed on the screen when the following programs are run? printing.c change_val.c And what does this function do? secret.c.
Senem Kumova Metin Spring2009 BINARY TREES && TREE TRAVERSALS Chapter 10 in A Book on C.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture22.
For loops For loops are controlled by a counter variable. for( c =init_value;c
CSC2100B Quick Sort and Merge Sort Xin 1. Quick Sort Efficient sorting algorithm Example of Divide and Conquer algorithm Two phases ◦ Partition phase.
Arrays Write a program that first reads in 20 integers and then asks the user whether they want to display all the even integers or all the odd integers.
אתחול מערך void main() { int i; int ar1[5]={7,3,4,5,2}; int ar2[]={9,3,3,4,6};/*the size is 5*/ int ar3[5]={3,2};/*the other nums are 0*/ int ar4[3];/*garbage*/
Functions Definition: Instruction block called by name Good design: Each function should perform one task and do it well Functions are the basic building.
Programming Summary. Exercise – Remove Duplicates Download remove_duplicates_ex.c and implement the function void remove_duplicates(Node *head); remove_duplicates()
1 CSE1301 Computer Programming: Lecture 35 Revision.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays 6.3Declaring Arrays 6.4Examples Using Arrays 6.5Passing.
Lecture 4 Feb 5 completion of recursion (inserting into a linked list as last item) analysis of algorithms – Chapter 2.
Jan Art of Programming Yangjun Chen Dept. Business Computing University of Winnipeg.
Arrays Ethan Cerami New York University Today n Array Basics (Review) n Random Number Example n Passing Arrays to Functions n Strings.
 2003 Prentice Hall, Inc. All rights reserved Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
CSE1301 Computer Programming: Revision. Topics Type of questions What do you need to know? About the exam Exam technique Sample questions.
1 Two-Dimensional Arrays. 2 Can be visualized as consisting m rows, each of n columns Syntax: datatype arrayname [row] [ column] ; Example: int val[3]
פוינטרים ומבנים. אתחול והדפסת מערך #include int * readArray(int size){ int *a, i; a= (int *) malloc (size* sizeof(int)); if (!a) return NULL; for (i=0;i
Programming Arrays. Question Write a program that reads 3 numbers from the user and print them in ascending order. How many variables do we need to store.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
1 1-d Arrays. 2 Array Many applications require multiple data items that have common characteristics  In mathematics, we often express such groups of.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
IKI 10100I: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100I: Data.
Chapter 6 Arrays Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Searching. The process used to find the location of a target among a list of objects Searching an array finds the index of first element in an array containing.
LAB#7. Insertion sort In the outer for loop, out starts at 1 and moves right. It marks the leftmost unsorted data. In the inner while loop, in starts.
How to start Visual Studio 2008 or 2010 (command-line program)
C Lecture Notes 1 Arrays Lecture 6. C Lecture Notes 2 6.1Introduction Arrays –Structures of related data items –Static entity – same size throughout program.
Pointers OVERVIEW.
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.
Comparison-Based Sorting & Analysis Smt Genap
Sort Algorithms.
LAB#6. 2 Overview Before we go to our lesson we must know about : 1. data structure. 2.Algorithms. data structure is an arrangement of data in a computer.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
1 Java linked list. Java linked list - definition ▪ Often in programming we are required to systematically store some type of information. A prime example.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Recursion. Circular Definition (not useful) E.g., E.g., Projenitor: one who produces an offspring Projenitor: one who produces an offspring Offspring:
Selection Sort main( ) { int a[ ] = { 17, 6, 13,12, 2 } ; int i, j, t ; for ( i = 0 ; i
Functions Programming Applications. Functions every C program must have a function called main program execution always begins with function main any.
Java linked list.
Stacks This presentation shows – how to implement the stack – how it can be used in real applications.
Linked List. Insert a node at the beginning #include struct node { int data; struct node* next; }; struct node* head; void Insert(int x) { node *temp.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
Week 12 Class Activities.
 Structures typedef struct student{ char name[30]; long id; int grades[8]; } Student_type, *pStudent_type;
Lecture 2. Algorithms and Algorithm Convention 1.
 Dynamic Memory Allocation  Linked Lists  void main() {{ ◦ FILE *file; ◦ char file_name[] = “file.txt”; ◦ if ((file = fopen(file_name, "w")) ==
Sort & Search Algorithms
Linked List :: Basic Concepts
ECE Application Programming
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
C Programming Tutorial – Part I
Linked list.
Recursion.
Arrays Outline Introduction Arrays Declaring Arrays
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
EECE.2160 ECE Application Programming
LINKED LIST.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
EECE.2160 ECE Application Programming
Presentation transcript:

 Last Lecture Reminder  Array Sorts  Exam Questions Examples  Open Questions ◦ Search Engines ◦ Operating Systems ◦ Multiple Files in Projects  Additional Lesson – before MOED ALEF

 Linked Lists  Files

2345 Head Next Next = NULL

typedef struct link{ int data; struct link *next; }link;

void main(){ link *head=NULL, *temp=NULL; int d; printf("Enter the list values:\n"); scanf ("%d",&d); while (d!=-1){ temp=(link *)malloc(sizeof(link)); if (!temp) break; temp->next=head; temp->data=d; head=temp; scanf ("%d",&d); }  A list is presented by its head

while(temp){ printf("%d ",temp->data); temp=temp->next; } while (head){ temp=head->next; free(head); head=temp; }

void free_list(link *head) { if (head== NULL) /* Finished freeing. Empty list */ return; free_list(head->next); /* Recursively free what’s ahead */ free(head); }

C Program STDIN STDOUT STDERR FILE1 FILE2

 stdin  stdout  stderr

#include void main(){ int n; printf("hello world"); fprintf(stdout,"hello world"); fprintf(stderr,"hello world"); fscanf(stdin,"%d", &n); scanf("%d", &n); }

#include void main(){ FILE *f1; f1 = fopen(“test1.txt","w"); if(!f1){ printf("Error opening file!\n"); return; } fprintf(f1,"hello world"); fclose(f1); }

#include void main(){ char ch; FILE *f1; f1 = fopen(“test2.txt","r"); if(!f1){ printf("Error opening file!\n"); return; } fscanf(f1,"%c",&ch); fclose(f1); }

 Bubble Sort  Selection Sort  Insertion Sort  Merge Sort  Quick Sort

#include void main() { int i, j, min, temp, nums[10]; for (i=0; i<SIZE; i++){ /*input*/ printf ("enter number\n"); scanf ("%d",&nums[i]); } for (i=0; i<SIZE; i++){ /*main loop*/ for (j=0; j<SIZE-i-1; j++) /*finding smaller*/ if (nums[j]>nums[j+1]) { temp = nums[j]; /*swapping*/ nums[j] = nums[j+1]; nums[j+1] = temp; } for (i=0; i<SIZE; i++) /*printing*/ printf ("%d\n",nums[i]); }

 Unsorted array:  Effective array of size 6:  Effective array of size 5:  Effective array of size 4:  Effective array of size 3:  Effective array of size 2:  Effective array of size 1:  Sorted array:        12 

#include void main() { int i, j, min, temp, nums[10]; for (i=0; i<10; i++){ /*input*/ printf ("enter number\n"); scanf ("%d",&nums[i]); } for (i=0; i<9; i++){ /*main loop*/ min = i; for (j=i+1; j<10; j++) /*finding minimum index*/ if (nums[j]<nums[min]) min = j; temp = nums[i]; /*swaping*/ nums[i] = nums[min]; nums[min] = temp; } for (i=0; i<10; i++) /*printing*/ printf ("%d\n",nums[i]); }

375912

#include void main() { int i, j, temp, nums[10]; for (i=0; i<10; i++){ /*input*/ printf ("enter number\n"); scanf ("%d",&nums[i]); } for (i=0; i<10; i++){ /*main loop*/ /*finding location of nums[j]*/ for (j=i; j>0 && nums[j]<nums[j-1]; j--){ temp = nums[j]; /*swaping*/ nums[j] = nums[j-1]; nums[j-1] = temp; } for (i=0; i<10; i++) /*printing*/ printf ("%d\n",nums[i]); }

void mergeSort(int ar[],int lo,int hi){ if (lo<hi) { int m=(lo+hi)/2; mergeSort(ar,lo, m); mergeSort(ar, m+1, hi); merge(ar, lo, m, hi); }

#define SIZE 100 void merge(int a[],int lo,int m, int hi){ int i, j, k, b[SIZE]; for (i=lo; i<=hi; i++) b[i]=a[i]; i=lo; j=m+1; k=lo; while (i<=m && j<=hi) if (b[i]<=b[j]) a[k++]=b[i++]; else a[k++]=b[j++]; while (i<=m) a[k++]=b[i++]; }

 What’s printed on the screen when the following programs are run? ◦ printing.c ◦ change_val.c  What does this function do? ◦ secret.c

 Implement a function such that – ◦ Input: string s that contains (among other things) parentheses ◦ Output: 1 if the parentheses’ nesting is legal, 0 otherwise ◦ For example – (()())() is legal, while ())() and (()(()) are not.  Write a program that accepts a string from the user and checks the parentheses.

 Write a structure of a point in 2D space and a distance function between two points  Write a program that gets an array of points from the user and calculates the largest distance between a pair of points in the array  The size of the array is given by the user before the points are read in  Solution – max_distance.c

 Implement a linked list where each item simply contains an integer  Input a number n from the user, and split the original list into two lists such that the first contains all the elements smaller than n, and the other contains all the others  Display both linked lists on the screen

 Define two structures – a point and a circle  Implement a function is_in_circle that accepts a point and a circle, and returns 1 if the point is in the circle, 0 otherwise  Write a program that accepts input from user in the following order: ◦ n = the number of circles ◦ A point  And outputs the number of circles containing that point  n is user input!`

 Search Engines  Operating Systems  Multiple Files in Projects