Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf 10.

Slides:



Advertisements
Similar presentations
Linear Lists – Linked List Representation
Advertisements

DATA STRUCTURES USING C++ Chapter 5
Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
PRESENTED BY MATTHEW GRAF AND LEE MIROWITZ Linked Lists.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
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.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Data Structures: A Pseudocode Approach with C
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
Recursion practice. Problem 0 Using recursion (and no arrays), write the code to read in a series of numbers (until EOF) and then print them backwards.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
Infix, Postfix, Prefix.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Lecture 5 Sept 12, 2011 Goals: Linked list (Chapter 3) list class in STL (section 3.3) implementing with linked lists.
Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf Internal.
Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf Search.
Lecture 4 Feb 5 completion of recursion (inserting into a linked list as last item) analysis of algorithms – Chapter 2.
Lecture 4 Sept 4 Goals: chapter 1 (completion) 1-d array examples Selection sorting Insertion sorting Max subsequence sum Algorithm analysis (Chapter 2)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
Variations of Linked Lists CS 308 – Data Structures.
Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf Trees.
Lecture 5 Feb 14, 2011 Goals: Linked list (Chapter 3) list class in STL (section 3.3) implementing with linked lists.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
CS162 - Topic #11 Lecture: Recursion –Problem solving with recursion –Work through examples to get used to the recursive process Programming Project –Any.
Data Structures Using Java1 Chapter 4 Linked Lists.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
Lecture 6 Feb 8, 2012 Goals: Linked list (Chapter 3) list class in STL (section 3.3) implementing with linked lists.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
Graphs & Trees Intro2CS – week General Graphs Nodes (Objects) can have more than one reference. Example: think of implementing a Class “Person”
Chapter 5 Linked Lists. © 2004 Pearson Addison-Wesley. All rights reserved 5 A-2 Preliminaries Options for implementing an ADT –Array Has a fixed size.
Algorithms and Data Structures
LINKED LIST’S EXAMPLES Salim Malakouti. Linked List? 523 Pointer Node ValuePointer.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
CSC 205 Programming II Lecture 15 Linked List – Other Variations.
Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf Order.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
Linked List.  Is a series of connected nodes, where each node is a data structure with data and pointer(s) Advantages over array implementation  Can.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
  A linked list is a collection of components called nodes  Every node (except the last one) contains the address of the next node  The address of.
LINKED LISTS.
CS162 - Topic #9 Lecture: Dynamic Data Structures –Deallocating all nodes in a LLL –Inserting nodes into sorted order Programming Assignment Questions.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Programming Circular Linked List.
Pointers and Linked Lists
Pointers and Linked Lists
UNIT – I Linked Lists.
Doubly Linked List Review - We are writing this code
Linked lists.
Mid Term Review Advanced Programming Ananda Gunawardena
Linked list insertion Head. Linked list insertion Head.
Dummy Nodes, Doubly Linked Lists and Circular Linked Lists
Pointers and Linked Lists
Chapter 17: Linked Lists Starting Out with C++ Early Objects
Recursive Linked List Operations
Containers: Queue and List
Linked Lists.
CS148 Introduction to Programming II
List Iterator Implementation
Linked lists.
More on Linked List Yumei Huo Department of Computer Science
Presentation transcript:

Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf 10 Questions on Linked Lists

Dept. of Computer Eng. & IT, Amirkabir University of Technology 1 Write efficient code to reverse the order of the contents of a singly linked list. Give the Big-Oh notation for the algorithm

Dept. of Computer Eng. & IT, Amirkabir University of Technology 2 Explain two different linked list variations (from a simply singly linked list), and list a positive and negative factor for each variation.

Dept. of Computer Eng. & IT, Amirkabir University of Technology 3 Crazy lists. Someone has written a class that creates CrazyLists. These are linked lists made up of singly linked nodes. But instead of making a nice sequential list, the class creates crazy linked structure. Some nodes data field point to other nodes instead of data. This leads to a branching structure that could look like this: myTail myHead next data

Dept. of Computer Eng. & IT, Amirkabir University of Technology Notes: all data pointers that are not shown are pointing to non-Node objects or are nul l. Write a method that determines the distance (number of links) from the head n ode to the tail node. the tail node could be pointing at ANY of the nodes in the structure There will be only one path from myHead to myTail the Crazy list will not contain cycles, circular references that create loops in th e structure.

Dept. of Computer Eng. & IT, Amirkabir University of Technology 4 The following function is supposed to return the length of a linked list. What is wrong?

Dept. of Computer Eng. & IT, Amirkabir University of Technology 5 The following function is supposed to recursively return the length of a linked list. What is wrong?

Dept. of Computer Eng. & IT, Amirkabir University of Technology 6 The following function is supposed to merge two linked lists. What is wrong?

Dept. of Computer Eng. & IT, Amirkabir University of Technology 7 The following function is supposed to print a Circular linked list. What is wrong?

Dept. of Computer Eng. & IT, Amirkabir University of Technology 8 The following function is supposed to insert a node in an ordered Circular linked list. What is wrong?

Dept. of Computer Eng. & IT, Amirkabir University of Technology 9 The following function is supposed to delete a node in an ordered Circular linked list. What is wrong?

Dept. of Computer Eng. & IT, Amirkabir University of Technology 10 با توجه به ليست داده شده در زير، خروجي هر يك از شبه كدهاي زير را مشخص كنيد. node *what(node *p) { if (p && p->link) return what(p->link->link); else return p; } node *q=what(first); cout data; void what(node *p) { if (p&& p->link) { what(p->link->link); cout data; what(p->link->link); } what(first);