Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
StackBubLink
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////// //StackBubLink: Stack Linked List and Bubble Sort //this code is created by Rezaul Hoque on September 01,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; /////////////////////////////////////////////////////////////////////////// #include <iostream> using namespace std; template <class V> class node { public: V data; node<V>* next; }; template <class T> class stack { node<T> * front,*rear; public: stack() { front =NULL; rear =NULL; } void add(T z) { node<T> *temp=new node<T>; temp->data = z; temp->next=NULL; if(isempty()) { front =temp; rear = front; } else { rear->next = temp; rear = temp; } } void remove() { if(isempty()) { cout<<"is empty"; } else if (rear == front){ delete front; rear= front=NULL; } else { node<T>* temp, *temp2; temp2= rear; temp= front; while (temp->next!= NULL) { temp2= temp; temp=temp->next; } rear = temp2; rear->next=NULL; delete temp; } } bool isempty() { if (front == NULL) return true; return false; } void bubble() { T i,j; T n=5; node<T> temp; for (T i=0; i<n; i++) { for (T j=0; j<n; j++) { if( front[i].data>front[j].data){ temp = front[i]; front[i]= front[j]; front[j]= temp; } } } } void display() { node<T>* temp; temp = front; while (temp!=NULL) { cout <<temp->data<<" "; temp=temp->next; } } }; int main() { stack<int> y; y.add(5); y.add(4); y.add(3); y.add(2); y.add(1); y.display (); std::cout<<"\n"; y.bubble(); y.display(); return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.32 sec, absolute running time: 0.14 sec, cpu time: 0.01 sec, memory peak: 6 Mb, absolute service time: 0,56 sec
edit mode
|
history
|
discussion
5 4 3 2 1 5 3 2 1