ساختمان داده ها لیستهای پیوندی

Slides:



Advertisements
Similar presentations
Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Advertisements

Section 2.5 Single-Linked Lists. A linked list is useful for inserting and removing at arbitrary locations The ArrayList is limited because its add and.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
CS 206 Introduction to Computer Science II 09 / 12 / 2008 Instructor: Michael Eckmann.
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 15 / 2008 Instructor: Michael Eckmann.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
Scott Grissom, copyright 2004 Ch 6 Data Structures Slide 1 Linear Data Structures Chapter 6 focuses on: Lists Stacks Queues You can skip the Array implementation.
12/18/2015ITK 2751 CollectionList A bstractSequentialList Vector Stack LinkedList {interface} AbstractList {abstract} ArrayList Java Provides a List interface.
CS212: DATASTRUCTURES Lecture 3: Searching 1. SinglyLinked list 2 A linked list is a series of connected nodes. Each node contains at least: – A piece.
CS 206 Introduction to Computer Science II 02 / 02 / 2009 Instructor: Michael Eckmann.
CSC 205 Programming II Lecture 15 Linked List – Other Variations.
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
ECE 636 Reconfigurable Computing Lecture 1 Course Introduction Prof
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN
Logic Gates and Logic Circuits
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN
Textbook and Syllabus Textbook: Topics:
IT 251 Computer Organization and Architecture
Adapted by Dr. Adel Ammar
Give qualifications of instructors: DAP
Sequential Logic.
Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,
K-map: Product-of-Sums Minimization
Lecturer PSOE Dan Garcia
IT 251 Computer Organization and Architecture
Number Systems Give qualifications of instructors:
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
Give qualifications of instructors: DAP
Textbook and Syllabus Textbook: Topics:
March 2006 Saeid Nooshabadi
Optimized Implementation of Logic Function
Textbook and Syllabus Textbook: Topics:
Sequential Circuits: Latches
Sequential Circuits: Latches
Optimized Implementation of Logic Function
“so many gadgets, so many aches” - NYT
ساختمان داده‌ها پیمایش درخت دودویی
Topic 6: Bitwise Instructions
ساختمان داده ها پشته ها Give qualifications of instructors: DAP
Sequential Circuits: Latches
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
پشته و صف پیوندی Give qualifications of instructors: DAP
Introduction to Electrical and Computer Engineering II
Sequential Circuits: Latches
ساختمان داده‌ها درختان و درختان دودویی
Optimized Implementation of Logic Function
ساختمان داده ها مرتب سازی درجی
پشته و صف پیوندی Give qualifications of instructors: DAP
Lecture 16 Section 6.2 Thu, Mar 1, 2007
To view, enable editing, select Slide Show, select From Beginning
ECE 697F Reconfigurable Computing Lecture 5 FPGA Routing
ECE 697F Reconfigurable Computing Lecture 4 FPGA Placement
March 2006 Saeid Nooshabadi
Give qualifications of instructors: DAP
CS148 Introduction to Programming II
Data Structures & Algorithms
NAND and XOR Implementation
Give qualifications of instructors: DAP
АВЛИГАТАЙ ТЭМЦЭХ ҮНДЭСНИЙ ХӨТӨЛБӨР /танилцуулга/
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 13 – Introduction to MIPS Instruction Representation I Lecturer PSOE.
March 2006 Saeid Nooshabadi
Without alpha_list.
Queues: Implemented using Linked Lists
Circuit Analysis Procedure by Dr. M
Dept of Electronics Engineering
Linked List Insert After
Digital Systems Section 3 Boolean Algebra. Digital Systems Section 3 Boolean Algebra.
CS 151 Digital Systems Design Lecture 1 Course Overview
Presentation transcript:

ساختمان داده ها لیستهای پیوندی ساختمان داده ها لیستهای پیوندی Give qualifications of instructors: DAP teaching computer architecture at Berkeley since 1977 Co-athor of textbook used in class Best known for being one of pioneers of RISC currently author of article on future of microprocessors in SciAm Sept 1995 RY took 152 as student, TAed 152,instructor in 152 undergrad and grad work at Berkeley joined NextGen to design fact 80x86 microprocessors one of architects of UltraSPARC fastest SPARC mper shipping this Fall

مشکل: آیا می توان داده ها را در ساختاری غیر از آرایه ذخیره کرد؟ مرور مشکل: آیا می توان داده ها را در ساختاری غیر از آرایه ذخیره کرد؟ اشیاء مستقل دارای انعطاف بیشتری هستند. از ارجاع برای پیدا کردن همسایه ها استفاده کنیم. تکرارگرها در لیستهای پیوندی اهمیت فراوانی دارند. امکان جستجو در بین اشیاء لیست. نسبت به آرایه پیاده سازی آسانتری دارد. اما درک بصری آن مشکل تر است. credential: bring a computer die photo wafer : This can be an hidden slide. I just want to use this to do my own planning. I have rearranged Culler’s lecture slides slightly and add more slides. This covers everything he covers in his first lecture (and more) but may We will save the fun part, “ Levels of Organization,” at the end (so student can stay awake): I will show the internal stricture of the SS10/20. Notes to Patterson: You may want to edit the slides in your section or add extra slides to taylor your needs.

پیاده سازیArrayList – حذف یک آیتم Operation: delete(2) A 1 2 maxsize-1 3 4 B C D E Remove an item at position 2 pos Count=4 pos=2 Count=5 پیاده سازی حذف و اضافه کردن عنصر سخت و کند است. باید حداکثر اندازه ی آرایه را از قبل بدانیم. اگر آرایه پر شد، باید اندازه ی آرایه را تغییر دهیم. بعضی اوقات تخصیص n عنصر متوالی حافظه امکان پذیر نیست.

یک پیاده سازی دیگر از لیست. لیست پیوندی b a c null فقط به میزان لازم حافظه مصرف می کند و می توان در صورت لزوم به صورت دینامیک حافظه مصرفی را تخصیص داد. نیازی به حرکت اشیاء وجود ندارد.

مزایای لیست پیوندی a b c d e null نودها می توانند در هر جای حافظه باشند. آدرس نود بعدی در شی جاری ذخیره می شود و رفتن به نود بعدی آسان است. حذف یا اضافه کردن آیتمها مستلزم حرکت بقیه ی آیتمها نیست. Object a b c d e null

لیست پیوندی تک پیوندی (SLList) هر نود دو فیلد دارد: لیست پیوندی ساده لیست پیوندی تک پیوندی (SLList) دنباله ای از نودها هر نود دو فیلد دارد: آیتم. آدرس نود بعدی. b a c null head مقدار این نود برابر a و یک لینک به نود b دارد.

تعریف نود یک نود انتزاعی تعریف کنید: مثالی از یک نود Employee . private class Node { private Object item; Node next; } مثالی از یک نود Employee . Employee e;

لیست پیوندی تک پیوندی -- head/tail دو متغییر مهم در لیست های تک پیوندی وجود دارند: head نشانگر شروع لیست tail نشانگر انتهای لیست tail head node1 node2 node3

متد Search() در لیست پیوندی اگر لیست خالی باشد null بر می گرداند. اگر لیست خالی نباشد: از head شروع می کنیم و دنبال نود مورد نظر می گردیم. اگر پیدا شد آنرا چاپ می کنیم. node1 node2 node3 head tail نود مورد نظر

متد Size() در لیست پیوندی اگر لیست خالی بود مقدار 0 را برمی گردانیم. اگر لیست خالی نبود، تعداد عناصر لیست را بر می گردانیم. node1 node2 node3 head tail

اضافه کردن یک نود جدید tail newNode head node1 node2 node3 head tail حالت 1: لیست خالی باشد. head و tail را برابر نود جدید قرار دهید. tail newNode head حالت 2: اگر لیست خالی نیست، جایی که نود باید اضافه شود را پیدا کنید. سه حالت وجود دارد: اضافه کردن به اول لیست. افزودن به آخر لیست. افزودن به وسط لیست. node1 node2 node3 head tail

حالت اول: افزودن نود جدید به ابتدای لیست. tail head head newNode node1 node2 node3

حالت دوم:افزودن به وسط لیست. فرض کنید newNode بین نودهای شماره ی 2 و 3 اضافه می شود. node1 node2 node4 tail head node3

حالت دوم:افزودن به وسط لیست. فرض کنید newNode بین نودهای شماره ی 2 و 3 اضافه می شود. node1 node2 node4 tail head node3 newNode

حالت دوم:افزودن به وسط لیست. فرض کنید newNode بین نودهای شماره ی 2 و 3 اضافه می شود. node1 node2 node4 tail head node3 newNode

حالت دوم:افزودن به وسط لیست. فرض کنید newNode بین نودهای شماره ی 2 و 3 اضافه می شود. node1 node2 node4 tail head node3 newNode

حالت سوم: افزودن به آخر لیست. node2 node3 tail node1 head

حالت سوم: افزودن به آخر لیست. node2 node3 tail node1 head newNode

حالت سوم: افزودن به آخر لیست. node2 node3 tail node1 head newNode

حالت سوم: افزودن به آخر لیست. node2 node3 tail node1 head tail newNode

نود مورد نظر هم head و هم tail است. حالت اول حذف نود نود مورد نظر هم head و هم tail است. head head=null after deletion node 1 tail tail=null

نود مورد نظر head است ولی tail نیست. حالت دوم حذف نود نود مورد نظر head است ولی tail نیست. فرض کنید نود 1 حذف می شود. node2 node3 tail head node1

نود مورد نظر head است ولی tail نیست. حالت دوم حذف نود نود مورد نظر head است ولی tail نیست. فرض کنید نود 1 حذف می شود. tail head node1 node2 node3

نود مورد نظر head است ولی tail نیست. حالت دوم حذف نود نود مورد نظر head است ولی tail نیست. فرض کنید نود 1 حذف می شود. tail head node2 node3

نود مورد نظر نه head است و نه tail حالت سوم حذف نود نود مورد نظر نه head است و نه tail فرض کنید نود 2 حذف می شود. tail head node1 node2 node3 To be deleted

نود مورد نظر نه head است و نه tail حالت سوم حذف نود نود مورد نظر نه head است و نه tail فرض کنید نود 2 حذف می شود. tail head node1 node2 node3 To be deleted

نود مورد نظر نه head است و نه tail حالت سوم حذف نود نود مورد نظر نه head است و نه tail فرض کنید نود 2 حذف می شود. tail head node1 node3

حالت چهارم حذف نود نود مورد نظر head نیست ولی tail هست. tail head node1 node2 node3

حالت چهارم حذف نود نود مورد نظر head نیست ولی tail هست. tail head node1 node2 node3

حالت چهارم حذف نود نود مورد نظر head نیست ولی tail هست. tail head node1 node2

اندازه ی لیست دلخواه است. اعمال روی داده ها کارآمد هستند. خلاصه اندازه ی لیست دلخواه است. اعمال روی داده ها کارآمد هستند. افزودن، حذف کردن و ... پیاده سازی لیست پیوندی از آرایه کارآمدتر است.