Cải thiện bài viết Lưu bài viết Các bộ là một loại container kết hợp trong đó mỗi phần tử phải là duy nhất, bởi vì giá trị của phần tử xác định nó. Giá trị của phần tử không thể được sửa đổi sau khi được thêm vào tập hợp, mặc dù có thể xóa và thêm giá trị sửa đổi của phần tử đó. set::empty() hàm trống () được sử dụng để kiểm tra xem bộ chứa đặt có trống hay không. Cú pháp: setname.empty() Parameters : No parameters are passed. Returns : True, if set is empty False, Otherwise Examples: Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True Lỗi và ngoại lệ 1. Nó có một bảo đảm ném không ngoại lệ.2. Hiển thị lỗi khi một tham số được truyền.
Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True0 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True1 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True2 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True3 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True4 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True6 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True2 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True8 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True0 True1 True2 True3 True4 True5 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True7 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True9 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True4 True2 True3 False3 True5 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True7 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 False8 False9 True7 Output: True
Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True0 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True1 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True2 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True3 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True4 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True0 True1 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True0 True1 True2 True3 True4 True5 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True7 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True9 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True4 True2 True3 False3 True5 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True7 Output: False
Các Input : 1, 5, 6, 3, 9, 2 Output : 26 Explanation - 1+5+6+3+9+2 = 26 Độ phức tạp về thời gian: O (1) Ứng dụng: Đưa ra một tập hợp các số nguyên, tìm tổng của tất cả các số nguyên.
Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True0 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True1 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True2 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True3 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True4 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True0 True1 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True6 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True2 #include <set> 9Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 using 1using 2True2 using 4True2 using 6Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 True7
Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True00 Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True5 False8 False9 True7 Output: 26 Thông thường, bạn sẽ có một thời gian khó khăn để có được một chuỗi trống ở đây, xem xét Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True05 bỏ qua không gian trắng (không gian, tab, newlines) ... nhưng bất kể, Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True06 thực sự trả về số lượng trận đấu thành công ... Từ trang người đàn ông:
Vì vậy, nếu bằng cách nào đó họ quản lý để có được một chuỗi trống (ví dụ Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True07), bạn chỉ có thể kiểm tra kết quả trả về.
Lưu ý bạn phải kiểm tra ít hơn vì trong ví dụ tôi đã đưa ra, bạn sẽ lấy lại Input : myset{1, 2, 3, 4, 5}; myset.empty(); Output : False Input : myset{}; myset.empty(); Output : True08, một lần nữa chi tiết trong trang Man:
Là chức năng trống trong c?Vâng, một chức năng không chấp nhận bất kỳ đối số nào, nó không trả lại bất cứ điều gì và không làm gì trong cơ thể của nó.
Làm thế nào kiểm tra xem tệp có trống C ++ không?Mã trên hoạt động một cách đơn giản: peek () sẽ nhìn vào luồng và quay lại, mà không cần xóa, ký tự tiếp theo. Nếu nó đến cuối tệp, nó trả về eof ().Ergo, chúng tôi chỉ nhìn trộm () tại luồng và xem đó có phải là eof (), vì một tệp trống không có gì để nhìn trộm.peek() will peek at the stream and return, without removing, the next character. If it reaches the end of file, it returns eof() . Ergo, we just peek() at the stream and see if it's eof() , since an empty file has nothing to peek at. |