CS112_19_Slides--Efficiency&ADT-1

CS112_19_Slides--Efficiency&ADT-1 - Efficiency and...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CS112 Fundamentals of Programming Abstractions Efficiency and ADTs Yinglin Wang CS Dept., SJTU CS112 Fundamentals of Programming Abstractions Solution to chp8 exercise 1 Main() { stackADT integerStack; int integer; integerStack=NewStack(); printf(”entera list of integers, ending with 0:” ); while(TRUE){ printf(“>” ); scanf(“%d” ; &integer); if(integer!=0) Push(integerStack, integer); else break; } printf(“Those integers in reverse order are:” ) ; while(!StackIsEmpty){ pringtf(“\n %d” , Pop(integerStack)); } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS112 Fundamentals of Programming Abstractions Solution to chp8 exercise 2 Main() { printf(”entera list of integers, ending with 0:” ); reverseIntegers(void) } void reverseIntegers(void){ int integer; printf(“>” ); scanf(“%d” ; &integer); if(integer=0) { printf(“Those integers in reverse order are:” ) ; return; } else {reverseIntegers()}; printf(“\n%d” , integer); } CS112 Fundamentals of Programming Abstractions Different strategies for representing data can have a significant effect on the efficiency of yr code. linked list is a useful data structure for insertion and deletion operations. Main points:
Background image of page 2
CS112 Fundamentals of Programming Abstractions Today we will discuss the implementation of an Editor Buffer, which is the topic of your next assignment. An Editor Buffer is the data structure that underlies text editing programs like Notepad. The first implementation we will consider is based on arrays. The picture here is the demonstration of program. CS112 Fundamentals of Programming Abstractions Buffer.h: see textbook 375-378 Typedef struct bufferCDT *bufferADT bufferADT NewBuffer(void) Void Freebuffer(bufferADT buffer) MoveCursorForward(bufferADT buffer) MoveCursorBackward(bufferADT buffer) MoveCursorToStart(bufferADT buffer) MoveCursorToEnd(bufferADT buffer) void InsertCharacter(bufferADT buffer,char ch) void DeleteCharacter(bufferADT buffer) void DisplayBuffer(bufferADT buffer)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS112 Fundamentals of Programming Abstractions Array Implementation of Editor Buffer struct bufferCDT { char text[MaxBuffer]; int length; int cursor; }; …… void MoveCursorBackward(bufferADT buffer) { if (buffer–>cursor > 0) buffer–>cursor –– ; } …… n The array implementation of the
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/06/2010 for the course CS 112 taught by Professor Yinlinwang during the Spring '08 term at Shanghai Jiao Tong University.

Page1 / 15

CS112_19_Slides--Efficiency&ADT-1 - Efficiency and...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online