Wednesday, January 23, 2013

Write a program that reverses alternate elements in a given linked list input: a->b->c->d->e, output should be b->a->d->c->e

Node reverseAlterante ( Node head) {
if ( head == null || == null )
return head;
Node r = reverseAlternate(;
Node t = ; = head; = r;
return t ;

Monday, January 21, 2013

Printing all possible subsets using BitMask


void PrintAllSubset(int n)
int mask,pos,i,j,noOfSubSet = 1<<n; // subset size 2^n subsets
if((i&(1<<j)) > 0)
printf("%d ",j+1);
int main()
int n;
while(scanf("%d",&n) == 1)
return 0;

Tuesday, December 11, 2012

Write a function to print all subsets of a certain size of the numbers from 1 to n

#include <iostream>
#include <stdio.h>

using namespace std;
const int MAX = 1000;
int a[MAX];
bool b[MAX];
void f1(int n, int k, int indexn, int indexk){
int i, j;
for(i = indexn; i <= n - k + indexk; i++){
if(!b[i]) {
b[i] = true;
a[indexk] = i;
if(indexk == k) {
for(j = 1; j <= k; j++) {
printf("%d ", a[j]);
} else {
f1(n, k, indexn + 1, indexk + 1);
b[i] = false;
void f(int n, int k) {
int i;
for(i = 1; i <= n; ++i) {
a[i] = i;
b[i] = false;
f1(n, k, 1, 1);

int main()
    int n,k;
    while(scanf("%d %d",&n,&k) == 2)

return 0;

Friday, November 23, 2012

Unable to establish a secure connection to iTunes/iPhone

"Could not establish a secure connection to the device."

Here's what you have to do. You need a backup of your old Mac prior to upgrading, or prior to wiping and reinstalling.

You need to open Console on your new mac, and see the error message when you plug your phone into itunes and get that error, this will show up in your console:

8/13/12 1:21:04.537 PM iTunes[491]: AMDeviceValidatePairing (thread 0x11c313000): Could not load pairing record /var/db/lockdown//<device id>.plist

Then you need to go to your time machine backup and navigate to that same folder, and find the missing file. Copy that file back to your new machine into the /var/db/lockdown and you will magically be able to access your device again.

Tuesday, November 13, 2012

Make Xcode(4.x) faster

How to make  xcode faster
  • Buying more memory.
  • Disable indexing if you are building out huge projects in Xcode. This can halve Xcode’s memory consumption.
  • Running Xcode in 32 bit. This is not an option for everyone, because it will exceed 4 GB in larger projects.
  • Reduce the number of build processes (again).
  • Restarting Xcode often (It doesn’t do a very good job cleaning up after itself).
  • Use clang as your compiler. Clang instances in general use less memory than Apple’s GCC 4.2.
  • Offload dependent targets which do not change often. Example: You will not need to rebuild third party libraries daily in most cases.
Indexing in xcode
Xcode 4 has an entirely new mechanism for indexing files in a workspace. An index is created for the entire workspace, so references across projects are resolved.
The indexer now uses the LLVM compiler 2.0 to parse source files. This results in improved performance and higher accuracy; most importantly, the interpretation of symbols for indexing more closely matches the interpretation of syntax at compile time.
The index is stored in the Index subdirectory of the workspace’s unique directory in ~/Library/Developer/Xcode/DerivedData. Manage this information (including deleting the index and other derived data of an orphaned project) in the Organizer.
Indexing is done in the background; the Activity View indicates when indexing is being performed. Until the index is ready, some functions that require the index may not be available (for example, Open Quickly); others may have degraded performance (for example, syntax coloring of system symbols). When the index is complete these features become available immediately.
it seems to be that XCode4 and 4.1 uses crazy amounts of Ram during indexing - like, 5gb or so(!), and thus if you’re on a machine with something like 12gb, there’s no problem, but if you’re on a laptop with only 2gb or so, you’ll have some pretty severe paging going on.

How to disable indexing
Open the Terminal  window , then type the following code in terminal and click enter.
defaults write IDEIndexDisable 1
Now restart your xcode and enjoy better performance.
How to Enable xcode indexing
if you upgraded your machine or you want some other features to be turned on if you need indexing service,  please follow the steps below.
Open the Terminal  window , then type the following code in terminal and click enter.
 defaults write IDEIndexDisable 0
defaults delete IDEIndexDisable
While you’re at it, you should delete the key you added as well:
defaults delete IDEIndexEnable
Now restart the xcode now you can see the indexing will start from now on wards.
Disabling SVN & GIT in xcode
disabling SVN and Git plugins of XCode. Simply go to /Developer/Library/Xcode/PrivatePlugins
Now find IDEGit.ideplugin and IDESubversion.ideplugin
Change names of both of above plugins so that xcode will not be able to execute them in future. Now restart your xcode and enjoy better performance.

Monday, August 06, 2012

Install iOS 6 beta on your devices

You're now ready to start installing betas on your devices. To do this, you'll need to use the newest version of iTunes which is 10.6.3 or you can do this through the xCode 4.5 developer preview. I recommend that developers use the xCode method while app testers are probably okay using the iTunes method unless the developer would prefer you to use xCode to submit feedback.

iTunes method

This time around there is no beta version of iTunes needed. Just make sure you're running the current version of iTunes which is 10.6.3. You can download it from Apple's website.
  1. Open iTunes 10.6.3 after you've installed it and plug in the device you'd like to install iOS 6 beta to.
  2. Choose your device from the left navigation pane. You'll see a Restore button. Hold down Alt+option (or Ctrl for PC users) and click Restore.
  3. A file browser window will pop up. Navigate to the iOS 6 beta firmware file you would like to install onto your device.
  4. iTunes will now begin to update your device to iOS 6 beta. Let it do its thing and you're pretty much done.
  5. Xcode method

    1. In XCode, under software version, you'll need to choose Other version.
    2. Then xCode will ask you to navigate to the .ipsw file that you would like to install (the beta firmware file). I typically save them on my desktop or somewhere in a folder that I can easily find.
    3. Select it and click Restore iPhone
    4. A warning will pop up telling you all data will be erased. Agree and your device will be restored to the beta version. You can then restore from a backup in iTunes or from iCloud like you normally would.
    5. Either update method will get you onto the beta. It's up to you to decide what method is most appropriate for your situation.

      For more Check this.

Downgrade iOS 6 Beta to iOS 5.1.1

If you went ahead and installed iOS 6 beta and determined the buggy nature of the first developer release isn’t for you, it’s time to downgrade. Most developers should know how to do this already, but if not this process is easy and you’ll be back to running iOS 5.1.1 in no time at all.
Downgrading is identical on an iPhone, iPad, or iPod touch.
  1. Turn the device off, connect it to the computer via USB, and launch iTunes
  2. Place the iOS device into DFU mode: with the device off, hold down the Power and Home buttons together for 10 seconds then release the power button, continue holding Home button until iTunes notifies you of a device in recovery mode being detected. The devices screen should stay black as if turned off.
  3. Restore within iTunes through either method a or b:
    • a: Restore from the iOS 5.1.1 backup you made prior to installing iOS 6 beta
    • b: Restore to iOS 5.1.1 IPSW by Option-Clicking the “Restore” button, and then restore from iCloud backup when finished
  4. Let iTunes restore back to iOS 5.1.1, the device will reboot when finished
Typically you can’t downgrade iOS versions so easily, but because Apple is still signing iOS 5.1.1 this allows downgrading to commence with minimal effort.