1 / 9

#include <iostream . h> void main ( void ) { int x, y, * p, * q; p = new int;

1. จงหาผลลัพธ์จากโปรแกรมต่อไปนี้. #include <iostream . h> void main ( void ) { int x, y, * p, * q; p = new int; * p = 7; x = * p + 2; y = * p; q = new int; * q = * p / 2; * q = * q * 4; cout << x << y << * p << * q; }. 2. กำหนดให้

selia
Télécharger la présentation

#include <iostream . h> void main ( void ) { int x, y, * p, * q; p = new int;

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 1.จงหาผลลัพธ์จากโปรแกรมต่อไปนี้1.จงหาผลลัพธ์จากโปรแกรมต่อไปนี้ #include <iostream.h> void main(void) { int x, y, *p, *q; p = new int; *p = 7; x = *p + 2; y = *p; q = new int; *q = *p / 2; *q = *q * 4; cout << x << y << *p << *q; }

  2. 2.กำหนดให้ typedef struct ptr { int id; float score; struct ptr *next; } Ptr; Ptr *p, *q, *r, *s, *t; id score p 1001 6  1003 5  1006 7  1009 4  q จงใช้คำสั่ง (Statement) เพียงคำสั่งเดียวเพื่อ • ให้ r ชี้ที่โหนดที่ 4 • ให้ s ชี้โหนดที่ 2 • เปลี่ยนรหัสของโหนดที่ 1 เป็น 2004 • ให้ q เปลี่ยนมาชี้ที่โหนดที่ 3 • เปลี่ยนคะแนนของโหนดที่ 3 เป็น 85 • ตัด 3 โหนดหลังทิ้ง ให้คงเหลือโหนดแรกในลิงค์ลิสต์เพียงโหนดเดียว • ตัด 2 โหนดหลังทิ้ง ให้ลิงค์ลิสต์คงเหลือโหนดที่ 1 กับโหนดที่ 2 • ตัดโหนดที่ 4 ทิ้ง แล้วนำโหนดใหม่ ดังภาพมาต่อเป็นโหนดที่ 4 แทน • ตัด 2 โหนดกลางทิ้ง ให้ลิงค์ลิสต์คงเหลือเพียงโหนดที่ 1 กับโหนดที่ 4 • ให้ฟิลด์ next ของโหนดที่ 4 ชี้ไปยังโหนดแรก t 1008 92 

  3. 3.จากภาพของ Link Listed ที่กำหนดให้ p info next r 4  6  8  5  จงวาดภาพของ Link Listed ภายหลังการทำคำสั่งข้างล่างนี้ • s = r; • r ->next->info = 9; • p = p->next; • p -> next = r; • r -> next = p; • p -> next = p; • p -> next -> next = r; • r -> next -> next = p-> next; • s = p -> next -> next; • r = r -> next -> next;

  4. 4.จงหาผลลัพธ์จากส่วนของโปรแกรมต่อไปนี้4.จงหาผลลัพธ์จากส่วนของโปรแกรมต่อไปนี้ info next • p = new Ptr; • q = new Ptr; • p -> info = 8; • q -> info = 3; • p = q; • p -> info = 2; • cout << p->info, q-> info; 5  3. p = new Ptr; q = new Ptr; p -> info = 2; p -> next = q; q -> next = NULL;; q -> info = 8; p -> next -> next = p; q -> info = q -> next -> info; p = q; p -> next -> info = 4; cout << p->info, q-> info; 2. p = new Ptr; p -> info = 4; q = new Ptr; q -> info = 6; p = new Ptr; p->info = q->info; q -> info = 7; cout << p->info, q-> info;

  5. 5.จงวาดภาพของ Link Listed ภายหลังทำคำสั่งต่อไปนี้ info link “ ”  p = new Ptr; strcpy (p->info, “HER”); p -> next = new Ptr; q = p -> next; strcpy (q -> info, “her”); q -> next = NULL;

  6. 6.จากภาพของ Link Listed ที่กำหนดให้ info link f “mom”  “dad”  8  “nanny”  จงวาดภาพของ Link Listed ภายหลังการทำคำสั่งข้างล่างนี้ • p = f -> link; • strcpy (p ->info, “uncle”); 2. q = f -> link; p = q -> link; q -> link = p -> link; delete p; 3. p = f; p = new Ptr; strcpy (f->info, “aunty”); f -> link = p;

  7. 7.จากภาพของ Circular Linked-listที่กำหนดให้ ref temp2 info link k 25 47 75 จงเขียนคำสั่งในการลบ Node ที่มี info = k

  8. 8.จากภาพของ Circular Linked-listที่กำหนดให้ temp ref2 ref1 info link 25 47 75 38 60 86 จงเขียนคำสั่งในการรวม Circular Linked-List ref1 temp ref2 25 47 75 38 60 86

  9. 9.จากภาพของ Circular Linked-listที่กำหนดให้ ref2 info link temp ref1 47 75 25 38 60 จงเขียนคำสั่งในการแยก (Split)Circular Linked-List ออกเป็น 2 วง ref2 temp ref1 47 75 25 38 60

More Related