Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8754077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:33:00+00:00 2026-06-13T13:33:00+00:00

I have to implement three different sorting algorithms using an Object-Oriented Approach and I

  • 0

I have to implement three different sorting algorithms using an Object-Oriented Approach and I have been thinking of the best method to combat this.

Basically, I think it should look like this:

-> Sort (Class, interface, Polymorphic)

Inherit:

-> Bubble Sort

-> Insertion Sort

-> QuickSort

If each of the sorts have the same interface then it would be easier to access the different methods of sorting, thus, meaning that when I come to add other sorting algorithms, I can easily implement them into the current design and class structure.

My questions are:

  • Is this a good approach to use?

  • Is there scope for me to use Templates? I.e. if I wanted to use Bubble, it would call the bubble sort, if I wanted to use Insertion it would call Insertion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:33:01+00:00Added an answer on June 13, 2026 at 1:33 pm

    As suggested use an interface (pure virtual class)

    Interface Method:

    class sort_algorithm_interface {
    public:
        virtual void sort(std::vector<int>& input) const  = 0;
    };
    
    class BubbleSort : public sort_algorithm_interface {
    public:
        virtual void sort(std::vector<int>& input) const {/* sort the input */}
    };
    
    class InsertionSort: public sort_algorithm_interface {
    public:
        virtual void sort(std::vector<int>& input) const {/* sort the input */}
    };
    
    class QuickSort: public sort_algorithm_interface {
    public:
        virtual void sort(std::vector<int>& input) const {/* sort the input */}
    };
    

    Now when you want to sort you simple do the following:

    sort_algorithm_interface& s = QuickSort(input);
    s.sort(input);
    

    Template Method:

    class BubbleSort  {
    public:
        void sort(std::vector<int>& input) const {/* sort the input */}
    };
    
    class InsertionSort {
    public:
        void sort(std::vector<int>& input) const {/* sort the input */}
    };
    
    class QuickSort {
    public:
        void sort(std::vector<int>& input) const {/* sort the input */}
    };
    
    template<typename Sort>
    class MySort {
        void sort(std::vector<int>& input) {
            Sort s;
            s.sort(begin, end);
        }
    }
    

    This is used as follows:

    MySort<QuickSort> s;
    s.sort(input);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to implement pinch zoom/in-out for PhotoView (a UIImageView instance) using
I have three different objects which act as input to create object A. The
I have three current thoughts on how to do this: re-implement AuthenticationService, which uses
I'm trying to implement tree algorithms in C. I have declared a extern struct
I am trying to decide among three different implementations. I have an IPerson interface,
I currently have a couple different user controls that provide the same functionality: three
We are creating three different websites using asp.net but for the user part we
I'm trying to implement dragable sorting and saving the order to mysql using php
I have been trying different techniques while designing this application, which to me is
I have a three different tables that I'm trying to join up correctly but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.