
I had a multidimensional array, which needed to be sorted by one of the keys. A simple method for implementing kstacks is to divide the array into k slots of size no/k each and assign the slots to various stacks, i.e., use arr1 0 to arr1 no/k-1 for the first stack and arr1 no/k to arr1 2no/k-1 for stack2, in which arr1 is the array to be used to implement two stacks and array size is no. Simple function to sort an array by a specific key. This does seems to work for N stacks in a single array - tasnimrock2k6 Septem Flag Reply.

For stack 1, use 0,n/3 For stack 2, use n/3,2n/3 For stack 3, use. Here is my solution-Approach 1- Go for a fixed division of an array means if we divide our array into 3 equal parts and push the elements of an array into three fixed-sized stacks.

Implement 3 stacks in a single array archive#
Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search then you can use another int array, and implement a linklist, and solve to problem with highest efficiency. This is a very common interview question 'Implement 3 stacks using a single Array or >List'.
