0% found this document useful (0 votes)
83 views4 pages

Renditja Me Bubble Sort (Zbrites) :: / (Më Poshtë Është Dhe Zgjidhja Për Insertion Sort)

The document describes Bubble Sort and Insertion Sort algorithms for sorting arrays. It includes pseudocode for both algorithms and sample output showing the arrays being sorted from highest to lowest using each algorithm. Example C++ code is provided to implement the sorting algorithms and print the sorted arrays.

Uploaded by

Kristian Shyti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views4 pages

Renditja Me Bubble Sort (Zbrites) :: / (Më Poshtë Është Dhe Zgjidhja Për Insertion Sort)

The document describes Bubble Sort and Insertion Sort algorithms for sorting arrays. It includes pseudocode for both algorithms and sample output showing the arrays being sorted from highest to lowest using each algorithm. Example C++ code is provided to implement the sorting algorithms and print the sorted arrays.

Uploaded by

Kristian Shyti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Renditja me Bubble Sort (zbrites):

22 19 14 11 5 7 9 16 6 3
22 19 14 11 7 9 16 6 5 3
22 19 14 11 9 16 7 6 5 3
22 19 14 11 16 9 7 6 5 3
22 19 14 16 11 9 7 6 5 3
22 19 16 14 11 9 7 6 5 3
22 19 16 14 11 9 7 6 5 3

Kodi i Bubble Sort (zbrites):


/* (më poshtë është dhe zgjidhja për Insertion Sort) */

#include<iostream>

#include<cstdlib>

using namespace std;

void bubblesort(int array[])

int i, j, m = 1;

int temp;

int nr = 10;

for(i = 1; (i <= nr) && m; i++)

m = 0;

for (j=0; j < (nr -1); j++)


{

if (array[j+1] > array[j])

temp = array[j];

array[j] = array[j+1];

array[j+1] = temp;

m = 1;

for (int i = 0; i < 10; i++)

cout << array[i] << " ";

cout << "\n";

return;

void printArray(int arr[])

int i;

for (i = 0; i < 10; i++)

cout << arr[i] << " ";

cout << "\n";

int main(){

int Tab[]={19,22,14,11,5,3,7,9,16,6};

bubblesort(Tab);
printArray(Tab);

return 0;

Renditja me Insertion Sort (zbrites):


22 19 14 11 5 7 9 16 6 3
22 19 14 11 5 3 7 9 16 6
22 19 14 11 5 3 7 9 16 6
22 19 14 11 5 3 7 9 16 6
22 19 14 11 7 5 3 9 16 6
22 19 14 11 9 7 5 3 16 6
22 19 16 14 11 9 7 5 3 6
22 19 16 14 11 9 7 6 5 3

Kodi i Insertion Sort (zbrites):

#include<iostream>

#include<cstdlib>

using namespace std;

void insertionsort(int array[])

int i, j, key, nr = 10;

for(j = 1; j < nr; j++)

key = array[j];

for(i = j - 1; (i >= 0) && (array[i] < key); i--)

{
array[i+1] = array[i];

array[i+1] = key;

for (int i = 0; i < 10; i++)

cout << array[i] << " ";

cout << "\n";

return;

void printArray(int arr[])

int i;

for (i = 0; i < 10; i++)

cout << arr[i] << " ";

cout << "\n";

int main(){

int Tab[]={19,22,14,11,5,3,7,9,16,6};

insertionsort(Tab);

printArray(Tab);

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy