本文整理汇总了C++中StaticArray::lsearch方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticArray::lsearch方法的具体用法?C++ StaticArray::lsearch怎么用?C++ StaticArray::lsearch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StaticArray
的用法示例。
在下文中一共展示了StaticArray::lsearch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
// print my name and this assignment's title
cout << "Lab 5A, Static Array Program \n";
cout << "Programmer: Haris Hanif\n";
cout << "Editor(s) used: Xcode\n";
cout << "Compiler(s) used: Xcode\n";
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
int num;
int arraysize=0;
string buf;
StaticArray<int,200> sArray;
for (int i=0; i < sArray.getCapacity(); i++)
{
cout << "Enter " ;
cout<< i+1;
cout<< " number or 'q' || 'Q' to exit: ";
cin >> buf;
if (buf =="Q"||buf=="q")
{
cout<<endl << "Here is the output datastructure size: ";
cout<<arraysize <<endl;
break;
}
else
{
num = atof (buf.c_str());
cin.ignore (1000,10);
sArray[i] = num;
}
cout << "\nList of entered values: " << endl;
for (int j=0; j<=i; j++)
{
cout << sArray[j] << ' ';
}
arraysize++;
cout << endl << endl;
}
cout << "Implementing Linear Search"<<endl;
cout << "\nEnter number to search or 'q' || 'Q' to exit:";
while (true)
{
cin >> buf;
if (buf == "Q" || buf == "q")
break;
else
{
num = atof (buf.c_str());
cin.ignore (1000,10);
cout << "\nNumber ";
cout<<num;
cout<<" in array location is in :";
cout<< sArray.lsearch(num);
cout<<" element" << endl;
cout << "\nenter a number to search or 'q' || 'Q' to exit: ";
}
}
}
示例2: main
int main()
{
// print my name and this assignment's title
cout << "Lab 5a, The \"MyStaticArray5a.cpp\" Program \n";
cout << "Programmer: JEREMY THOMPSON\n";
cout << "Editor(s) used: JNotePad\n";
cout << "Compiler(s) used: VC++ 2013\n";
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl;
StaticArray<int, 1000> a;
string buf;
int i = 0;
bool input = true;
cout << "Enter a number: ";
cin >> buf;
cin.ignore(1000, '\n');
while (input)
{
// quit upon entry of q or Q
if (buf == "q" || buf == "Q")
input = false;
else
{
a[i++] = atoi(buf.c_str());
cout << "Enter a number or press Q or q to quit: ";
cin >> buf;
cin.ignore(1000, '\n');
}
}
// output number of values before 'Q' or 'q'
if (!input)
cout << "Number of values entered: " << i << endl;
// output unsorted list of entered values
// comma or space-delimited
for (int j = 0; j < i; j++)
cout << a[j] << ", ";
// search loop for an element using lsearch function
bool search = true;
while (search)
{
cout << "\nEnter an element to search for: ";
cin >> buf;
// quit upon entry of q or Q
if (buf == "q" || buf == "Q")
search = false;
else
{
int j = atoi(buf.c_str());
cout << "Entered value was found at index: " << a.lsearch(j) << endl;
}
}
cout << "\nPress ENTER to continue...";
cin.get();
}