fork download
  1. #include <cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. void bubblesort (int list[],int length);
  6.  
  7. int seqsearch(int list[],int len,int ele);
  8.  
  9. int main()
  10.  
  11. {
  12.  
  13. int list[20],n,i;
  14.  
  15. int search;
  16.  
  17. int ele;
  18.  
  19. cout<<
  20.  
  21. "Enter the size of the list:";
  22.  
  23. cin>>n;
  24.  
  25. cout<<
  26.  
  27. "Enter elements:";
  28.  
  29. for(i=0;i<n;i++)
  30.  
  31. {
  32.  
  33. cin>>list[i];
  34.  
  35. }
  36.  
  37. cout<<
  38.  
  39. "Enter element to look up:" ;
  40.  
  41. cin>> ele;
  42.  
  43. bubblesort (list,n) ;
  44.  
  45. search=seqsearch(list,n,ele);
  46.  
  47. if(search==-1)
  48.  
  49. {
  50.  
  51. cout<<
  52.  
  53. "Search Was Unsuccessful";
  54.  
  55. }
  56.  
  57. else
  58.  
  59. cout<<
  60.  
  61. "Element Found at:"<<search<<endl;
  62.  
  63. cout<<"Sorted array is"<<endl;
  64. for(i=0;i<n;i++)
  65. {
  66. cout << list[i]<<" ";
  67. }
  68. }
  69.  
  70. void
  71.  
  72. bubblesort (int list[],int size)
  73.  
  74. {
  75.  
  76. int temp, i,j;
  77.  
  78. for(i=0;i<size-1;i++)
  79.  
  80. {
  81.  
  82. for (j=0;j<size-i-1;j++)
  83.  
  84. {
  85.  
  86. if (list [j]>list[j+1])
  87.  
  88. {
  89.  
  90. temp=list[j];
  91.  
  92. list[j]=list[j+1];
  93.  
  94. list[j+1]=temp;
  95.  
  96. }
  97.  
  98. }
  99.  
  100. }
  101.  
  102. }
  103.  
  104. int
  105.  
  106. seqsearch (int list [], int size, int element)
  107.  
  108. {
  109.  
  110. int loc;
  111.  
  112. bool found = false;
  113.  
  114. for(loc=0 ; loc<size;loc++)
  115.  
  116. {
  117.  
  118. if(list[loc]==element)
  119.  
  120. {
  121.  
  122. found=true;
  123.  
  124. break;
  125.  
  126. }
  127.  
  128. }
  129.  
  130. if(found)
  131.  
  132.  
  133. return loc;
  134.  
  135.  
  136. else
  137.  
  138. return -1;
  139.  
  140. }
Runtime error #stdin #stdout 4.66s 2732KB
stdin
Standard input is empty
stdout
Enter the size of the list: