我想问 cpp ( C++ ) 中的 lower_bound 当应用于未排序的数组时表现如何。我的意思是当我运行以下程序时。
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int arr[]={8,9,10,1,2,3};
auto itr= lower_bound(arr,arr+6,7);
cout<<*itr<<endl;
}
Run Code Online (Sandbox Code Playgroud)
它的输出为“2”。但根据 lower_bound 的定义,它将迭代器提供给第一个失败的 '<' 和 'val' 元素。那么根据这个定义,答案不应该是‘8’吗,因为“8不小于7”。我知道它适用于排序数组,但我想知道这个值背后是否有逻辑,或者它是一个垃圾。
谢谢。
我有布局文件custom_lock.xml.它有3个子布局.问题是当我尝试从MainActivity.java访问布局的元素时,它返回null.它让我疯狂.请帮我.谢谢.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:name="@+id/place1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center"
android:text="Place"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:name="@+id/listofapps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_blue_light"
android:text="List of Apps" />
<ListView
android:name="@+id/sites"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_green_light" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:name="@+id/calories"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_purple"
android:text="Health Data" />
<ListView
android:name="@+id/dialer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/darker_gray" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
以下是我的MainActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_lock); …Run Code Online (Sandbox Code Playgroud)