// sorting stack
stack<int> sortedStack(stack<int> Stack) {
int tmpStack[Stack.size()];
int i=0;
while (!Stack.empty()) {
tmpStack[i++]=Stack.top();
Stack.top();
}
sort(tmpStack, tmpStack+i);
int j=0;
while (j<i) {
Stack.push(tmpStack[j++]);
}
return Stack;
}
stack<int> Stack;
// insertion to the sorted stack
Stack.push(item);
Stack=sortedStack(Stack);
// sorting queue
queue<int> sortedQueue(queue<int> Queue) {
int tmpQueue[Queue.size()];
int i=0;
while (!Queue.empty()) {
tmpQueue[i++]=Queue.front();
Queue.pop();
}
sort(tmpQueue, tmpQueue+i);
int j=0;
while (j<i) {
Queue.push(tmpQueue[j++]);
}
return Queue;
}
queue<int> Queue;
// insertion to the sorted queue
Queue.push(item);
Queue=sortedQueue(Queue);
// sorting list
list<int> sortedList(list<int> List) {
int tmpList[List.size()];
int i=0;
while (!List.empty()) {
tmpList[i++]=List.back();
List.pop_back();
}
sort(tmpList, tmpList+i);
int j=0;
while (j<i) {
List.push_back(tmpList[j++]);
}
return List;
}
list<int> List;
// insertion to the sorted list
List.push_back(item);
List=sortedList(List);
Comments
Leave a comment