Linked Structures, Project 1: Linked List Bryce Boe 2013/10/16 CS24, Fall 2013.

Slides:



Advertisements
Similar presentations
Linked Lists Mohammed Almashat CS /03/2006.
Advertisements

Linked Lists.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
COMP 1402 Winter 2009 Tutorial #8 malloc / calloc / realloc.
C Lab 3 C Arraylist Implementation. Goals ●Review ○ Referencing/Dereferencing ○ Free ●realloc and memmove ●ArrayList ●Debugging with GDB.
Project 1 Overview (List ADT), Array List Bryce Boe 2013/10/14 CS24, Fall 2013.
CS 261- Winter 2009 Dynamic Array Queue and Deque.
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,
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Dynamic Data Structures H&K Chapter 14 Instructor – Gokcen Cilingir Cpt S 121 (July 26, 2011) Washington State University.
Digression on Stack and Heaps CS-502 (EMC) Fall A Short Digression on Stacks and Heaps CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
Pointers and Dynamic Variables. Objectives on completion of this topic, students should be able to: Correctly allocate data dynamically * Use the new.
CS 106 Introduction to Computer Science I 03 / 03 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 08 / 2010 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
Chapter 17 Linked List.
Linked Structures, Project 1: Linked List Bryce Boe 2013/07/11 CS24, Summer 2013 C.
Priority Queues and Heaps Bryce Boe 2013/11/20 CS24, Fall 2013.
Recursion Bryce Boe 2013/11/18 CS24, Fall Outline Wednesday Recap Lab 7 Iterative Solution Recursion Binary Tree Traversals Lab 7 Recursive Solution.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
1 Linked Lists (continued (continued)) Lecture 5 (maybe) Copying and sorting singly linked lists Lists with head and last nodes Doubly linked lists Append/Circular.
Introduction of Engineering (ENGR 10) Guest Lecture March 24, 2014.
Comparing AlgorithmsCSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Complexity Reading: Kolman, Sections 4.6, 5.2, and 5.3.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
CS261 – Recitation 5 Fall Outline Assignment 3: Memory and Timing Tests Binary Search Algorithm Binary Search Tree Add/Remove examples 1.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
Pointers in C++. 7a-2 Pointers "pointer" is a basic type like int or double value of a pointer variable contains the location, or address in memory, of.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
M180: Data Structures & Algorithms in Java Linked Lists Arab Open University 1.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Separate Compilation Bryce Boe 2013/10/09 CS24, Fall 2013.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
1 Chapter 6 Methods for Making Data Structures. 2 Dynamic Arrays in Data Structures In almost every data structure, we want functions for inserting and.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
1 Joe Meehean. 2  empty is the queue empty  size  enqueue (add) add item to end of queue  dequeue (remove) remove and return item at front of queue.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
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:
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
Amortized Analysis and Heaps Intro David Kauchak cs302 Spring 2013.
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
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.
CSE 220 – C Programming malloc, calloc, realloc.
UNIT – I Linked Lists.
Programming Abstractions
Dynamic Memory CSCE 121 J. Michael Moore.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Circular Buffers, Linked Lists
C++ Classes and Data Structures Jeffrey S. Childs
Arrays and Linked Lists
understanding memory usage by a c++ program
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
Linked List.
Introduction to C++ Linear Linked Lists
Lists.
Data Structures & Algorithms
Linked List Intro CSCE 121.
Traversing a Linked List
Presentation transcript:

Linked Structures, Project 1: Linked List Bryce Boe 2013/10/16 CS24, Fall 2013

Outline Lab 3 Review Project 1 Notes Linked Structures

LAB 3 REVIEW

Student Comments “I haven't learned anything new but instead have spent hours writing a variety of loops and random code searching for some bug…” “What I've been doing was unceasingly putting in random functions and random parameters for the whole day trying to figure out some bugs.” “And the worse thing is that I don't even know how it came out when I found it…”

Lab 3 was supposed to be challenging Many of you practiced fuzz testing – Great way to perform black-box testing to attempt to find bugs An exercise in trying something and testing if it worked – Code, compile, test (repeat over and over) Now we’ll make sense of the bugs

Project 1 Notes Do not use static or global variables (you will lose significant points if you rely on them) You must validate all memory allocations – if an allocation fails make sure you don’t leak other memory Get the array list working up to size N before dealing with reallocation

LINKED STRUCTURES

What’s wrong with using arrays to store data? Arrays require continuous chunks of memory Unless the array is full, there is wasted space Expanding the array is typically done by doubling the size – Worst case time: Have to copy all the existing items – Hint: realloc does this for you (recall how realloc is implemented)

How long does it take? Appending an item to a non-full array? Appending an item to a full-array? Removing an item from the end of the array? Removing an item from the beginning of the array? Accessing an element in the middle of the

Single-link Node structure struct Node { int _data; struct Node *_next; }

Node allocation walkthrough Add an initial node Add another node at the beginning Add another node at the end Remove a node at the beginning Remove a node at the end

How can we access the data of specific elements? The data of the second element? – head->_next->_data The data of the third element? – head->_next->_next->_data; (Generally) The data of the nth element? struct Node *tmp = head; for (int i = 0; i < n; ++i) tmp = tmp->_next; tmp->_data;