TAILIEUCHUNG - C Programming for Scientists & Engineers phần 10

chứa địa chỉ của nó. Các biểu hiện tiếp tục trong báo cáo trong khi thử nghiệm, trong đó có chương trình sao lưu để làm ở phía trên cùng của vòng lặp bởi vì người dùng không nhập 'kết thúc'. Người sử dụng là một lần nữa nhắc nhở cho đầu vào. Giả sử rằng họ cung cấp một tên trái cây thứ hai, một cấu trúc dữ liệu được phân bổ. | Dynamic memory management and linked lists 129 contain its address. The continuation expression in the while statement is now tested which takes the program back up to the do at the top of the loop because the user did not enter end . The user is again prompted for input. Assuming that they supply a second fruit name another data structure is allocated. Since first-ptr now holds the address of the first allocated data structure the test expression in the if statement is now TRUE causing the first part of the if-else statement to be executed. This uses the present value of current-fruit-ptr now dotted in Figure c to store the address of the new data structure in the member next of the previous structure. Following this current-fruit-ptr is updated to make the newly allocated structure the current one prior to storing the user supplied name and setting next in the current structure to NULL. Figure c shows the state of the linked list and its associated pointers at the end of the second pass through the do-while loop. Similarly Figure d shows the situation after the user has supplied a third name. Note again that current-fruit-ptr is used to change the value of next in the previously allocated structure prior to being assigned the address of the new structure. Finally supposing that the user entered five names followed by end the linked list and its pointers will be as shown in Figure e and the program will leave the do-while loop. In order to display the full list of fruits the address stored in first-ptr is now copied to current-fruit-ptr so that current-fruit-ptr points to the start of the list. A while loop is then used to firstly print the name stored within the current structure and secondly update current-fruit-ptr by assigning to it the value of next in the current structure. The while loop terminates when current-fruit-ptr has been assigned a NULL value indicating that the end of the list has been reached. In comparison to Program Program

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.