Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BubDoubLinArray
//g++ 7.4.0 //Sorting and searching template array using bubble sort and linear search in double linked list //code is created by Rezaul Hoque on March 25,2021 //please contact at jewelmrh@yahoo.com #include <iostream> #include <bits/stdc++.h> using namespace std; template <class T> class node{ public: T val; int p; int q; node<T>* next; node<T>* prev; void bubble(node<T> a[], T n); int lins( node<T> a[], int n, T thing); }; template <class T> void node<T>::bubble(node<T> a[], T n) { T i,j; node<T> temp; for (T i=0; i<n; i++) { for (T j=0; j<n; j++) { if( a[i].val < a[j].val){ temp = a[i]; a[i] = a[j]; a[j] = temp; } } } } template <class T> int node<T>::lins(node<T> a[], int n, T thing) { for(int i=0; i<n; i++){ if(a[i].val ==thing) { return i; } } return -1; } int main() { const int max=3; node<char>* a; a = new node<char>[max]; a[0].prev=NULL; a[2].next = NULL; for(int i=0; i<max; i++) { a[i].next = a[i+2].prev; } a[0].val={'E'}; a[1].val={'D'}; a[2].val={'C'}; a[0].p={4}; a[1].p={2}; a[2].p = {6}; a[0].q={5}; a[1].q={4}; a[2].q = {8}; cout<<"After bubble sort:\n"; a->bubble(a, max); for(int i=0; i<max; i++) { cout<<a[i].val<<"\t"<<a[i].p<<"\t"<<a[i].q<<endl; cout<<"\n"; } char thing; cout<<"Enter the thing you look for:\n"; cin>>thing; if(a->lins(a,3,thing) != -1) { cout<<thing<<" is at a["<<a->lins(a, 3,thing)<<"].\n"; } else { cout <<thing<<" is not found.\n"; } return 0; }
run
|
edit
|
history
|
help
0
Dar
string iteration performance
MapGrocery
顺序表的实现——静态分配
BinTree
VecHotel2
cref
Straight Max-Min
UtilityPair2
sa