Computer Science 2 5-17-18.

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Pointers and Data Structures 1 Yinzhi Cao Modified from slides made by Prof Goce Trajcevski.
COMP171 Fall 2005 Lists.
Linked Lists.
James Tam Linked Lists in Pascal Linked Lists In this section of notes you will learn how to create and manage a dynamic list.
Data Structures: A Pseudocode Approach with C
DATA STRUCTURE “Linked Lists” SHINTA P STMIK MDP April 2011.
Info 3.3. Chapter 3.3 Recursive Data Structures Part 2 : Binary Trees.
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
1 Compiler Construction Intermediate Code Generation.
Data Structures: A Pseudocode Approach with C
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Linked List
CS 106 Introduction to Computer Science I 04 / 30 / 2007 Last lecture :( Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 12 / 04 / 2006 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 06 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 12 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 15 / 2008 Instructor: Michael Eckmann.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
CS 206 Introduction to Computer Science II 02 / 09 / 2009 Instructor: Michael Eckmann.
Linked Lists Spring Linked Lists / Slide 2 List Overview * Linked lists n Abstract data type (ADT) * Basic operations of linked lists n Insert,
Introduction to Data Structures. Data Structures A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Tree.
Data Abstraction CS 201j: Engineering Software University of Virginia Computer Science Nathanael Paul
Chapter 5 – Dynamic Data Structure Part 2: Linked List DATA STRUCTURES & ALGORITHMS Teacher: Nguyen Do Thai Nguyen
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
1 Working with Pointers An exercise in destroying your computer.
3 Data. Software And Data Data Data element – a single, meaningful unit of data. Name Social Security Number Data structure – a set of related data elements.
CS2006- Data Structures I Chapter 5 Linked Lists III.
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
Ceng-112 Data Structures ISerap ATAY, Ph. D. 1 Chapter 3 – Part 2 Linear Lists.
CS 206 Introduction to Computer Science II 02 / 02 / 2009 Instructor: Michael Eckmann.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
Data Structures Lakshmish Ramaswamy. Removing Element public Object remove(int index){ Object retobj; if(index size){ throw IndexOutOfBoundsException.
Data Structure & Algorithms
CS32 Discussion Section 1B Week 3 TA: Hao Yu (Cody)
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear.
INTRODUCTION TO DATA STRUCTURES 1. DATA STRUCTURES A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Mohammed I DAABO COURSE CODE: CSC 355 COURSE TITLE: Data Structures.
Review Array Array Elements Accessing array elements
5.13 Recursion Recursive functions Functions that call themselves
Indexing and hashing.
UNIT – I Linked Lists.
Chapter 15 Lists Objectives
Lists CS 3358.
Lecture - 6 On Data Structures
Binary Search Trees.
Lecture 7 Algorithm Analysis
CS200: Algorithms Analysis
B Tree Adhiraj Goel 1RV07IS004.
Computer Science Dynamics.
Computer Science 2 Hashing
Computer Science 2 Outline/Learning Objectives for the day:
Linked List.
Computer Science Dynamics.
Computer Science Sorting.
Chapter 11 Data Structures 1.
Computer Science 1 1/19/2011 On the record (paper) write the following
Computer Science 2: Trees
Go to the Audacity website. (You can search for Audacity in Google).
Deleting from a binary tree
Computer Science 2 Tally Arrays 2/4/2016.
CS 2 Records 2/22/2018.
Computer Science 2 More Trees.
Deleting from a binary tree
More Trees 5/9/2-017 Be able to dry run a program that uses trees
Computer Science 2 Queue.
Time to finish first stack program
Presentation transcript:

Computer Science 2 5-17-18

Be able to find someone in a linked list Learning Targets Be able to find someone in a linked list Be able to delete someone from a linked list. Be able to create a simple track database.

Type ptrtype = ^rectype; rectype = record data:string; phone:string; next:ptrtype; end; Warm-up With a partner, write a procedure for finding someone’s phone number that is in a linked list. procedure FindNode(top:ptrtype; person:string);

Finding a node pseudo code procedure FindNode(top:ptrtype;person:integer) Search for a node with the value equal to person in the list. If such a node is found, show the value. procedure FindNode(top:ptrtype; person:string); Var currNode:ptrtype; begin currNode := top; while (currNode<>nil) and (currNode^.data<> person) do currNode := currNode^.next; end; if (currNode<>nil) then writeln (person, ‘ phone number is ’, currNode^.phone) else writeln(person, ‘ was not found in the list’); End;

Deleting a node Steps Like InsertNode, there are two special cases DeleteNode(top:ptrtype; person:string) Delete a node with the value equal to person from the list. Steps Find the desirable node (similar to FindNode) Set the pointer of the predecessor of the found node to the successor of the found node Release the memory occupied by the found node Like InsertNode, there are two special cases Delete first node Delete the node in middle or at the end of the list

Deleting a node Pseudocode Procedure DeleteNode(var top:ptrtype; person:string); Var prevNode, currNode:ptrtype; begin prevNode := nil; currNode := top; while (currNode<>nil) and (currNode^.data <> person) do prevNode := currNode; currNode := currNode^.next; end; if (currNode<>nil)then if (prevNode<> nil) then prevNode^.next := currNode^.next; dispose(currNode); end else top := currNode^.next; End; Try to find the node with its value equal to x

Deleting a node Procedure DeleteNode(var top:ptrtype; person:string); prevNode, currNode:ptrtype; begin prevNode := nil; currNode := top; while (currNode<>nil) and (currNode^.data <> person) do prevNode := currNode; currNode := currNode^.next; end; if (currNode<>nil)then if (prevNode<> nil) then prevNode^.next := currNode^.next; dispose(currNode); end else top := currNode^.next; End; prevNode currNode

Deleting a node Procedure DeleteNode(var top:ptrtype; person:string); prevNode, currNode:ptrtype; begin prevNode := nil; currNode := top; while (currNode<>nil) and (currNode^.data <> person) do prevNode := currNode; currNode := currNode^.next; end; if (currNode<>nil)then if (prevNode<> nil) then prevNode^.next := currNode^.next; dispose(currNode); end else top := currNode^.next; End; front currNode

Insertion Linked List Assignment #2 You will be creating a program for the running track events. (Note: Time will be kept in seconds) Name Event (Push: Let it support the participant running in up to 3 events.) Best Time

What it needs to do. Enter the information Find a participant Insertion linked list by name Find a participant Show their event and best time or say they are not in the list Show all participants, events and times in order based on their name Delete a person from the list Pushes Save to a file (Linked list to file) Load from a file (File to linked list) Enter an event and show all participants in that event Enter and event and give lane assignments based on speed for an 8 lane track 4, 5, 3, 6, 2, 7, 1, 8