Practical training c ++ language design -- sorting and searching of array elements

Source: Internet
Author: User

I learned how to sort array elements, how to search for array elements, and how to find and sort array elements in the C ++ library.

Program:
// Lab10_2.cpp
# Include <iostream>
# Include <algorithm>
Using namespace STD;

Void displayarray (int A [], int N)
{Cout <Endl <"your input array is :";
For (INT I = 0; I <n; I ++) cout <A [I] <"";
Cout <Endl ;}
Int main ()
{Int N, J;
Cout <"Enter the number of values you want to enter :";
Cin> N;
Int * P;
P = new int [N];
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
For (INT I = 0; I <n; I ++)
{Cout <"input number" <I + 1 <"value:" <Endl;
Cin> J;
P [I] = J ;}
Displayarray (p, N );
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Int L = 1;
While (l)
{Int K;
Int * q;
Cout <Endl <"Enter the value you want to search :";
Cin> K;
Q = find (p, p + n-1, k );
If (Q! = P + N-1)
Cout <"the value you searched for" <k <"is in the" <q-p + 1 <"bit! "<Endl;
Else
Cout <"the value you searched for" <k <"does not exist! "<Endl;
Cout <"continue searching? "<Endl <" by 1/No by 0 "<Endl;
Cin> L;
} Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.