1. Trang chủ
  2. » Công Nghệ Thông Tin

Cấu trúc dữ liệu bài thực hành tuần 1

7 3 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

Tài liệu Cấu trúc dữ liệu bài thực hành tuần 1 được thực hiện với các nội dung: Cài đặt các thuật toán sắp xếp trên mảng, Selectionsort, Insertsort, Interchangesort, Bubblesort, Quicksort, Heap sort. Mời các bạn cùng tham khảo nội dung chi tiết tài liệu.

CẤU TRÚC DỮ LIỆU BÀI THỰC HÀNH TUẦN Nội dung: Cài đặt thuật toán xếp mảng Selectionsort Insertsort Interchangesort Bubblesort Quicksort Heap sort Hướng dẫn: Mở Visual Studio 2010 Chọn Program File – Microsoft Visual Studio 2010 http://sites.google.com/site/cosodulieuvlth Tạo project mới: File – New – Project Chọn loại project Visual C++ -> Win32 Console Application Điền tên project Chọn OK http://sites.google.com/site/cosodulieuvlth Chọn Finish Chương trình khởi tạo project có sẵn hàm main http://sites.google.com/site/cosodulieuvlth Viết hàm nhập, xuất mảng sửa lại hàm main Nhấn Ctrl+Shift+B để biên dịch http://sites.google.com/site/cosodulieuvlth Nếu chương trình khơng có lỗi báo: Build: succeeded, failed Nhấn F5 để chạy chương trình Nhập vào số phần tử mảng Nhập giá trị phần tử Chương trình in mảng nhập http://sites.google.com/site/cosodulieuvlth Viết tiếp hàm: void hoanvi(int &a,int &b); // hoán vị số int a, b void selectionsort(int a[],int n); // xếp chọn trực tiếp void insertsort(int a[],int n); // xếp chèn trực tiếp void interchangesort(int a[],int n); // xếp đổi chỗ trực tiếp void bubblesort(int a[],int n); // xếp bọt void quicksort(int a[],int l,int r); // xếp nhanh // Heap sort void shift(int a,int l,int r); void createheap(int a[],int n); void heapsort(int a[],int n); Sửa lại hàm main để gọi thuật tốn xếp Hàm nhập xuất mảng dùng lệnh cin, cout để viết ví dụ sau: http://sites.google.com/site/cosodulieuvlth http://sites.google.com/site/cosodulieuvlth

Ngày đăng: 09/05/2021, 17:57

w