ساختمان داده ها لیستهای پیوندی ساختمان داده ها لیستهای پیوندی 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
اندازه ی لیست دلخواه است. اعمال روی داده ها کارآمد هستند. خلاصه اندازه ی لیست دلخواه است. اعمال روی داده ها کارآمد هستند. افزودن، حذف کردن و ... پیاده سازی لیست پیوندی از آرایه کارآمدتر است.