Tuesday, October 1, 2013

Program to convert expression infix to prefix

//infix to prefix

#include<stdio.h>

#include<string.h>

#define SIZE 10

int pr(char op)
{
if(op=='*' || op=='/')
return 3;
if(op=='+' || op=='-')
return 2;
else
return 0;
}

char stack[SIZE];
int top=-1;

void push(char op)
{
stack[++top]=op;
}

char pop()
{
return stack[top--];
}

void polish(char infix[],char prefix[])
{
int i,l,j=0;
char op;
strrev(infix);
l=strlen(infix);
infix[l]='(';
infix[l+1]='\0';
push(')');
for(i=0;infix[i]!='\0';i++)
{
if(isalpha(infix[i]))
{
prefix[j++]=infix[i];
continue;
}
if(infix[i]==')')
{
push(infix[i]);
continue;
}
if(infix[i]=='(')
{
while((op=pop())!=')')
prefix[j++]=op;
}
else
{
while(pr(infix[i])<pr(stack[top]))
prefix[j++]=pop();
push(infix[i]);
}

}
prefix[j]='\0';
strrev(prefix);
}

int main()
{
char infix[20],prefix[20];
printf("\nEnter the infix : ");
gets(infix);
polish(infix,prefix);
printf("\nprefix : %s",prefix);

return 0;
}

Program to convert express infix to postfix in stack using array

//infix to postfix





#include<stdio.h>

#include<string.h>

#define SIZE 10

int pr(char op)
{
if(op=='*' || op=='/')
return 3;
if(op=='+' || op=='-')
return 2;
else
return 0;
}

char stack[SIZE];
int top=-1;

void push(char op)
{
stack[++top]=op;
}

char pop()
{
return stack[top--];
}

void rev_polish(char infix[],char postfix[])
{
int i,l,j=0;
char op;
l=strlen(infix);
infix[l]=')';
infix[l+1]='\0';
push('(');
for(i=0;infix[i]!='\0';i++)
{
if(isalpha(infix[i]))
{
postfix[j++]=infix[i];
continue;
}
if(infix[i]=='(')
{
push(infix[i]);
continue;
}
if(infix[i]==')')
{
while((op=pop())!='(')
postfix[j++]=op;
}
else
{
while(pr(infix[i])<=pr(stack[top]))
postfix[j++]=pop();
push(infix[i]);
}

}
postfix[j]='\0';
}

int main()
{
char infix[20],postfix[20];
printf("\nEnter the infix : ");
gets(infix);
rev_polish(infix,postfix);
printf("\nPostfix : %s",postfix);
return 0;
}

circular queue using linked list



#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<stdlib.h>

#define SIZE 5

int Q[SIZE],front=-1,rear=-1;

void insert(int x)
{
if( (front==0 && rear==SIZE-1) || front==rear+1)
{
printf("\nOverflow");
return ;
}
if(rear==-1)
front=rear=0;
else
if(rear==SIZE-1)
rear=0;
else
rear++;
Q[rear]=x;
}

int del()
{
int item;
if(front==-1)
{
printf("\nUnderflow");
return -9999;
}
item=Q[front];
if(front==rear)
front=rear=-1;
else
if(front==SIZE-1)
front=0;
else
front++;
return item;
}

int main()
{
int n,ch;
while(1)
{
printf("\n\t\t\tMenu");
printf("\n\t\t\t1 : Insert");
printf("\n\t\t\t2 : Deletion");
printf("\n\t\t\t3 : Exit");
printf("\n\t\t\tEnter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the item :");
scanf("%d",&n);
insert(n);
break;
case 2:
n=del();
if(n!=-9999)
printf("\nPopped item : %d",n);
break;
case 3:
exit(0);
default:
printf("\nInvalid Choice");
}
}
return 0;
}

priority queue using linked list

//priority queue using linked list

#include<stdio.h>
#include<conio.h>
#include<malloc.h>

typedef struct node
{
int info,pr;
struct node *next;
}node;
node *start=NULL;

void insert_at_end(int x,int p);
void insert_at_beg(int x,int p);
void insert_at_specific(int ,int, int);
void del_at_beg();
void insert(int x,int p);

int main()
{
int n,po,ch,p;
while(1)
{
printf("\n\t\t\tMenu");
printf("\n\t\t\t1 : Insertion");
printf("\n\t\t\t2 : Deletion");
printf("\n\t\t\t3 : Exit");
printf("\n\t\t\tEnter ur choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the info :");
scanf("%d",&n);
printf("\nEnter the priority :");
scanf("%d",&p);
insert(n,p);
break;
case 2:
del_at_beg();
break;
case 3:
exit(0);
default:
printf("\nInvalid choice");
}
}
return 0;
}

void insert_at_end(int x, int p)
{
node *temp,*new_node;
new_node=(node*)malloc(sizeof(node));
new_node->info=x;
new_node->pr=p;
new_node->next=NULL;
if(start==NULL)
start=new_node;
else
{
temp=start;
while(temp->next!=NULL)
temp=temp->next;
temp->next=new_node;
}
}

void insert_at_beg(int x,int p)
{
node *new_node;
new_node=(node*)malloc(sizeof(node));
new_node->info=x;
new_node->pr=p;
new_node->next=start;
start=new_node;
}

void insert_at_specific(int x,int p,int po)
{
int i;
node *new_node,*temp;
if(po<1 || po>count()+1)
{
printf("\nInvalid position");
return;
}
if(po==1)
insert_at_beg(x,p);
else
{
if(po==count()+1)
insert_at_end(x,p);
else
{
new_node=(node*)malloc(sizeof(node));
new_node->info=x;
new_node->pr=p;
new_node->next=NULL;
temp=start;
for(i=1;i<po-1;i++)
temp=temp->next;
new_node->next=temp->next;
temp->next=new_node;
}
}
}


int count()
{
node *temp;
int c=0;
for(temp=start;temp!=NULL;temp=temp->next)
c++;
return c;
}

void del_at_beg()
{
node *temp;
if(start==NULL)
{
printf("\nList Empty");
return;
}
temp=start;
start=start->next;
printf("\nDeleted node : %d",temp->info);
printf("\nDeleted priority : %d",temp->pr);
free(temp);
}

void insert(int x,int p)
{
node *temp;
int po=0;
if(start==NULL)
{
insert_at_beg(x,p);
return;
}
temp=start;
while(temp!=NULL)
{
if(temp->pr >= p)
{
po++;
temp=temp->next;
}
else
break;
}
insert_at_specific(x,p,po+1);
}

implemention of linked list(add at beg,add at end, add at specific position, delete at beg, delete at end, delete at specific postion )


//add_at_beg, add_at_end,add_at_specific,del_at_beg, del_at_end,del_at_specific

#include<stdio.h>

#include<conio.h>
#include<malloc.h>

typedef struct node
{
int info;
struct node *next;
}node;
node *start=NULL;

void insert_at_end(int x);
void insert_at_beg(int x);
void insert_at_specific(int ,int);
void disp();
void del_at_beg();
void del_at_end();
void del_at_specific(int po);
int seq_search(int item);
void sort();

int main()
{
int n,po,ch;
while(1)
{
printf("\n\t\t\tMenu");
printf("\n\t\t\t1 : Insertion at end");
printf("\n\t\t\t2 : Insertion at beg");
printf("\n\t\t\t3 : Insertion at specific");
printf("\n\t\t\t4 : Display");
printf("\n\t\t\t5 : Deletion at beg");
printf("\n\t\t\t6 : Deletion at end");
printf("\n\t\t\t7 : Deletion at specific");
printf("\n\t\t\t8 : Search");
printf("\n\t\t\t9 : Sorting");
printf("\n\t\t\t10 : Exit");
printf("\n\t\t\tEnter ur choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the info :");
scanf("%d",&n);
insert_at_end(n);
break;
case 2:
printf("\nEnter the info :");
scanf("%d",&n);
insert_at_beg(n);
break;
case 3:
printf("\nEnter the position :");
scanf("%d",&po);
printf("\nEnter the info :");
scanf("%d",&n);
insert_at_specific(n,po);
break;
case 4:
disp();
break;
case 5:
del_at_beg();
break;
case 6:
del_at_end();
break;
case 7:
printf("\nEnter the position :");
scanf("%d",&po);
del_at_specific(po);
break;
case 8:
printf("\nEnter the item :");
scanf("%d",&n);
po=seq_search(n);
if(po!=-1)
printf("\nFound at %d",po);
else
printf("\nNot Found.");
break;
case 9:
sort();
break;
case 10:
exit(0);
default:
printf("\nInvalid choice");
}
}
return 0;
}

void insert_at_end(int x)
{
node *temp,*new_node;
new_node=(node*)malloc(sizeof(node));
new_node->info=x;
new_node->next=NULL;
if(start==NULL)
start=new_node;
else
{
temp=start;
while(temp->next!=NULL)
temp=temp->next;
temp->next=new_node;
}
}

void insert_at_beg(int x)
{
node *new_node;
new_node=(node*)malloc(sizeof(node));
new_node->info=x;
new_node->next=start;
start=new_node;
}

void insert_at_specific(int x,int po)
{
int i;
node *new_node,*temp;
if(po<1 || po>count()+1)
{
printf("\nInvalid position");
return;
}
if(po==1)
insert_at_beg(x);
else
{
if(po==count()+1)
insert_at_end(x);
else
{
new_node=(node*)malloc(sizeof(node));
new_node->info=x;
new_node->next=NULL;
temp=start;
for(i=1;i<po-1;i++)
temp=temp->next;
new_node->next=temp->next;
temp->next=new_node;
}
}
}

void disp()
{
node *temp;
printf("\nElements in the list are : ");
for(temp=start;temp!=NULL;temp=temp->next)
printf("%d ",temp->info);
}

int count()
{
node *temp;
int c=0;
for(temp=start;temp!=NULL;temp=temp->next)
c++;
return c;
}

void del_at_beg()
{
node *temp;
if(start==NULL)
{
printf("\nList Empty");
return;
}
temp=start;
start=start->next;
printf("\nDeleted node is %d",temp->info);
free(temp);
}

void del_at_end()
{
node *temp;
int i;
if(start==NULL)
{
printf("\nList Empty");
return;
}
if(count()==1)
{
del_at_beg();
return;
}
temp=start;
for(i=1;i<count()-1;i++)
temp=temp->next;
printf("\nDeleted node is %d",temp->next->info);
free(temp->next);
temp->next=NULL;
}

void del_at_specific(int po)
{
int i;
node *temp,*temp1;
temp=start;
for(i=1;i<po-1;i++)
temp=temp->next;
temp1=temp->next;
temp->next=temp1->next;
printf("\nDeleted node is %d",temp->info);
free(temp1);
}

int seq_search(int item)
{
int po=0;
node *temp;
temp=start;
while(temp!=NULL)
{
po++;
if(temp->info==item)
return po;
temp=temp->next;
}
return -1;
}


void sort()
{
int t;
node *i,*j;
for(i=start;i!=NULL;i=i->next)
{
for(j=i->next;j!=NULL;j=j->next)
{
if(i->info > j->info)
{
t=i->info;
i->info=j->info;
j->info=t;
}
}
}
}

merge two linked list

#include<stdio.h>
#include<conio.h>
#include<malloc.h>

typedef struct node
{
int info;
struct node *next;
}node;

node *start1=NULL,*start2=NULL,*start3=NULL,*cur;

void make_node(int x)
{
cur=(node*)malloc(sizeof(node)) ;
cur->info=x;
cur->next=NULL;
}
void create_list(node **first, int x)
{
node *temp;
make_node(x);
if(*first==NULL)
*first=cur;
else
{
temp=*first;
while(temp->next!=NULL)
temp=temp->next;
temp->next=cur;
}
}
void traverse(node *first)
{
while(first!=NULL)
{
printf("\t%d",first->info);
first=first->next;
}
}
void sort(node *first)
{
node *n;
int temp;
for(;first!=NULL;first=first->next)
{
for(n=first->next;n!=NULL;n=n->next)
{
if(first->info > n->info)
{
temp=first->info;
first->info=n->info;
n->info=temp;
}
}
}
}

void merge()
{
node *m,*n;
m=start1;
n=start2;
while(m!=NULL && n!=NULL)
{
if(m->info < n->info)
{
create_list(&start3,m->info);
m=m->next;
}
else
{
create_list(&start3,n->info);
n=n->next;
}
}
while(m!=NULL)
{
create_list(&start3,m->info);
m=m->next;
}
while(n!=NULL)
{
create_list(&start3,n->info);
n=n->next;
}
}

int main()
{
int n;
char ch;
printf("\nCreate the first list :\n");
do
{
printf("\nEnter the info :");
scanf("%d",&n);
create_list(&start1,n);
printf("\nWant to continue?[y/n] :");
ch=getche();
}while(toupper(ch)=='Y');
printf("\nCreate the second list :\n");
do
{
printf("\nEnter the info :");
scanf("%d",&n);
create_list(&start2,n);
printf("\nWant to continue?[y/n] :");
ch=getche();
}while(toupper(ch)=='Y');
printf("\n\nFirst List :");
traverse(start1);
printf("\n\nSecond List :");
traverse(start2);
sort(start1);
sort(start2);
merge();
printf("\n\nMerged List :");
traverse(start3);
getch();
return 0;
}

Friday, September 6, 2013

C program for Addition of Sparse Matrix

/*  Add Sparse Matrix...- Contributed by Tushar Anand  */


#include<stdio.h>
#include<stdlib.h>
struct sparse
{
        int *arr;
        int cnt;
};
int c=0;
void create(struct sparse *s)
{
        int arr[3][3];
        int l,i,j;
        s->cnt=0;
        printf("Enter elements\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        scanf("%d",&arr[i][j]);
                        if(arr[i][j]!=0)
                        s->cnt++;
                }//for j
        }//for i
        if(s->cnt>9/2)
        {
                printf("\nNot Sparse matrix\n");
        }
        else
        {
                c=1;
                s->arr=(int *)malloc(sizeof(int)*(s->cnt+1)*3);
                *(s->arr+0)=3;
                *(s->arr+1)=3;
                *(s->arr+2)=s->cnt;
                l=3;
                for(i=0;i<3;i++)
                {
                        for(j=0;j<3;j++)
                        {
                                if(arr[i][j]!=0)
                                {
                                        *(s->arr+l+0)=i;
                                        *(s->arr+l+1)=j;
                                        *(s->arr+l+2)=arr[i][j];
                                        l=l+3;
                                }//if
                        }//for j
                }//for i
        }
}
display(struct sparse *s)
{
        int i;
        for(i=0;i<(s->cnt)*3+3;i++)
        {
                if(i%3==0&&i!=0)
                printf("\n");
                printf("%d\t",*(s->arr+i));
        }//for i
}
void add(struct sparse *s1,struct sparse *s2,struct sparse *s3)
{
        int i,j,k=3,l=3,m=3,flag=0;    
        s3->arr=(int *)malloc(sizeof(int)*(s1->cnt+s2->cnt+1)*3);
        *(s3->arr+0)=3;
        *(s3->arr+1)=3;
        for(i=0;i<3;i++)
        {
                if(*(s1->arr+m+0)==i &&*(s2->arr+l+0)==i)
                {
                        for(j=0;j<3;j++)
                        {
                                if(*(s1->arr+m+1)==j&&*(s2->arr+l+1)==j && *(s1->arr+m+0)==i &&*(s2->arr+l+0)==i)
                                {
                                        *(s3->arr+k+0)=i;
                                        *(s3->arr+k+1)=j;
                                        *(s3->arr+k+2)=*(s1->arr+m+2)+*(s2->arr+l+2);
                                        k+=3;
                                        flag++;
                                        m+=3;
                                        l+=3;
                                }
                                else if(*(s1->arr+m+1)==j && *(s1->arr+m+0)==i)
                                {
                                        *(s3->arr+k+0)=i;
                                        *(s3->arr+k+1)=j;
                                        *(s3->arr+k+2)=*(s1->arr+m+2);
                                        flag++;
                                        k+=3;
                                        m+=3;
                                }
                                else if(*(s2->arr+l+1)==j && *(s2->arr+l+0)==i)
                                {
                                        *(s3->arr+k+0)=i;
                                        *(s3->arr+k+1)=j;
                                        *(s3->arr+k+2)=*(s2->arr+l+2);
                                        flag++;
                                        k+=3;
                                        l+=3;
                                }
                        }
                }
                else if(*(s1->arr+m+0)==i)
                {
                        for(j=0;j<3;j++)
                        {
                                *(s3->arr+k+0)=i;
                                *(s3->arr+k+1)=j;
                                *(s3->arr+k+2)=*(s1->arr+m+2);
                                flag++;
                                k+=3;
                                m+=3;
                        }
                }
                else if(*(s2->arr+l+0)==i)
                {
                        for(j=0;j<3;j++)
                        {
                                *(s3->arr+k+0)=i;
                                *(s3->arr+k+1)=j;
                                *(s3->arr+k+2)=*(s2->arr+l+2);
                                flag++;
                                k+=3;
                                l+=3;
                        }
                }
        }
        *(s3->arr+2)=flag;
        s3->cnt=flag;
}
void main()
{
        struct sparse head,head1,head2;
        create(&head);
        create(&head1);
        if(c==1)
        {
        display(&head);
        display(&head1);
        add(&head,&head1,&head2);
        printf("\n\nAdded matrix :: \n\n");
        display(&head2);
        }
}

Saturday, August 31, 2013

Simple stacks implementation using linked list : PUSH , POP

/*simple stacks implementation using linked list */

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>

struct stack
 {
int data;
  struct node *link;
 };
void push(struct stack **top,int val)
 {
  struct stack *temp;
  temp =(struct stack *)malloc(sizeof(struct stack));
  if(temp==NULL)
  printf("\nstack overflow\n");
temp->data=val;
temp->link=*top;
*top=temp;
 }
int pop(struct stack **top)
 {
  struct stack *temp;
  int ret;
  if(*top==NULL)
  {
  printf("\nstack underflow\n");
  return NULL;
  }
  temp=*top;
  ret=temp->data;
  (*top)=(*top)->link;
  free(temp);
  return ret;
 }

void main()
 {
  struct stack *s1=NULL;
  int i;
 
  push(&s1,12);
  push(&s1,20);
  push(&s1,1);
  push(&s1,13);
 
  i=pop(&s1);          // i=13
  i=pop(&s1);          // i=1
 
  printf("%d\n",i);   // prints 1
 }


Simple Stacks Implementation using arrays : PUSH , POP

/*Simple Stacks Implementation : PUSH , POP*/

#include<stdio.h>

#define max 10

struct stack
 {
  int arr[max];
  int top;
 };
void ini(struct stack *s)
 {
  s->top=(-1);
 }
void push(struct stack *s,int val)
 {
  if(s->top==(max-1))
  {
  printf("\nSTACK OVERFLOW\n");
  return;
 }

  s->top++;
  s->arr[s->top]=val;

 }
int pop(struct stack *s)
 {
  int data;
  if(s->top==-1)
    {
  printf("\nSTACK UNDERFLOW\n");
return;
}


data=s->arr[s->top];
s->top--;
return data;

}
void main()
 {
  struct stack s1;
  int i;
  ini(&s1);
  push(&s1,10);
  push(&s1,40);
  push(&s1,20);
  i=pop(&s1);
  printf("\n%d\n",i);
  i=pop(&s1);
  printf("\n%d\n",i);
  i=pop(&s1);
  printf("\n%d\n",i);
 }




Wednesday, August 28, 2013

C++ program to count member function calls

/* C++ program to count member funtion calls */

#include<iostream>
using namespace std;

class A
 {
  int data;
  static int i,j;
  public:
  void input()
  {
  cout<<"enter num : ";
  cin>>data;
  i++;
  }
  void display()
  {
  cout<<"\nnum is "<<data<<endl;
  j++;
  }
  void count()
  {
  cout<<"\nInput calls = "<<i<<"\nDisplay calls = "<<j<<endl;
  }
 };
int A :: i=0;
int A :: j=0;

int main()
 {
  A A1;
  int c;
  do
  {
  cout<<"\n1.INPUT\n2.OUTPUT\n3.COUNT\n4.EXIT\nENTER CHOICE : ";
  cin>>c;
  switch(c)
  {
  case 1:
  A1.input();
  break;
case 2:
  A1.display();
  break;
case 3:
  A1.count();
  break;
default :
return 0;
  }
  }
  while(c);
  return 0;
 }






C++ program using constructor,destructor

/* C++ program using constructor,destructor */



#include<iostream>
using namespace std;
class t
{
  int hour;
  int min;
 public:
 // void input();
  t(int,int);
  t();
  void display(void)
  {
  cout<<"hour="<<hour<<"\n";
  cout<<"min="<<min<<"\n";
  }
  t(t &t11)
  {
  hour=t11.hour;
  min=t11.min;
  }
  ~t()
  {
   cout<<"\ndestroyed\n";
  }
};
t::t(int h,int m)
  {
   hour=h;
   min=m;
  }
 t::t()
    {
     hour=0;
     min=0;
    }

int main()
{
 t t1;
 cout<<"\nobject1 "<<"\n";
 t1.display();
 t1=t(2,45);
 cout<<"\nobject2"<<"\n";
 t1.display();
 t t2(t1);
 cout<<"\nobject3 "<<"\n";
 t2.display();
 return 0;
}

C++ program to swap numbers between two objects of different class

 /* c++ program to swap no between two objects of diff class */

#include<iostream>
using namespace std;
class A
{
public:

 int num1;

 void input()
 {
 cout<<"\nenter the number:";
 cin>>num1;
 }
 void display()
 {
 cout<<num1<<endl;
 }
friend class B;
};
class B
{
public:

 int num2;

 void input()
{
 cout<<"\nenter the second number:";
 cin>>num2;
}
void display()
{
cout<<num2<<endl;
}
friend class A;
};
void swapping(A &A1,B &B1)
{
int temp;
temp=A1.num1;
A1.num1=B1.num2;
B1.num2=temp;
}
int main()
{
A A11;
B B11;
A11.input();
B11.input();
cout<<"number before swapping:";
A11.display();
B11.display();
swapping(A11,B11);
cout<<"number after swapping:";
A11.display();
B11.display();
return 0;
}

Program to Convert Infix expression to prefix Expression

/*Program to Convert Infix expression to prefix Expression*/

#include <stdio.h>
#include <string.h>
#include<malloc.h>

#define MAX 50

struct infix
{
char target[MAX];
char stack[MAX];
char *s,*t;
int top,l;
};



void initinfix ( struct infix *p )
{
p -> top = -1 ;
strcpy ( p -> target, "" ) ;
strcpy ( p -> stack, "" ) ;
p -> l = 0 ;
}

void strrev(char *x)
 {
int i,j=0;
char *t;
t=(char *)malloc(sizeof(char)*strlen(x));
for(i=strlen(x)-1;i>=0;i--)
{
t[j++]=x[i];
}
x=t;
//return x;
 }
void setexpr ( struct infix *p, char *str )
{
p->s=str;
strrev(p->s);
p->l=strlen(p->s);
*(p->target+p->l)='\0';
p->t=p->target + (p->l-1);
}


void push ( struct infix *p, char c )
{
if (p->top==MAX-1)
printf ("Stack is full.\n");
else
{
p->top++;
p->stack[p->top]=c;
}
}


char pop (struct infix *p)
{
if (p->top==-1)
{
printf("Stack is empty.\n");
return -1;
}
else
{
char item = p->stack[p->top];
p->top--;
return item ;
}
}

int priority (char c)
{

if(c=='*'||c=='/'||c=='%')
return 2 ;
else
{
if(c=='+'||c=='-')
return 1 ;

else return 0 ;
}
}

void convert (struct infix *p)
{
char opr;

while (*(p->s))
{
if(*(p->s) == ' ' || *(p->s) == '\t')
{
p->s++;
continue ;
}

if (isdigit(*(p->s))||isalpha(*(p->s)))
{
while(isdigit(*(p->s)) || isalpha(*(p->s)))
{
*(p->t) = *(p->s);
p->s++;
p->t--;
}
}

if(*(p->s)==')')
{
push(p,*(p->s));
p->s++;
}

if (*(p->s) == '*' || *(p->s) == '+'||  *(p->s) == '/' || *(p->s ) == '%'|| *(p->s) == '-'|| *(p->s) == '$' )
{
if (p->top!=-1)
{
opr=pop(p);

while (priority(opr)>priority(*(p->s)))
{
*(p->t) = opr;
p->t--;
opr = pop(p);
}
push (p,opr);
push (p,*(p->s));
}
else
push (p,*(p->s));
p->s++;
}

if(*(p->s) == '(')
{
opr=pop(p);
while (opr!=')')
{
*(p->t)=opr;
p->t--;
opr=pop(p) ;
}
p->s++;
}
}

while (p->top!=-1)
{
opr=pop(p);
*(p->t)=opr;
p->t--;
}
p->t++;
}




void show (struct infix p)
{
while(*(p.t))
{
printf(" %c",*(p.t));
p.t++;
}
}






int main()
{
struct infix q ;
char expr[MAX] ;

initinfix(&q);

printf("Enter infix expression : " ) ;
gets(expr);

setexpr(&q,expr);
convert(&q);

printf ("\nThe Prefix expression is: ");
show(q);
printf("\n");

return 0;
}




Monday, August 19, 2013

Steve Jobs : Brief Biography


Steven Paul Jobs

Youth

Steven Paul Jobs was born on February 24, 1955 in San Francisco, California. His unwed biological parents, Joanne Schieble and Abdulfattah Jandali, put him up for adoption. Steve was adopted by Paul and Clara Jobs, a lower-middle-class couple, who moved to the suburban city of Mountain View a couple of years later.
Paul Jobs and his son
The Santa Clara county, south of the Bay Area, became known as Silicon Valley in the early 1950s after the sprouting of a myriad of semi-conductor companies. As a result, young Steve Jobs grew up in a neighborhood of engineers working on electronics and other gizmos in their garages on weekends. This shaped his interest in the field as he grew up. At age 13, he met one the most important persons in his life: 18-year-old Stephen Wozniak, an electronics wiz kid, and, like Steve, an incorrigible prankster.
Five years later, when Steve Jobs reached college age, he told his parents he wanted to enroll in Reed College — an expensive liberal arts college up in Oregon. Even though the tuition fees were astronomical for the poor couple, they had promised their son's biological parents he would get a college education, so they relented. Steve spent only one semester at Reed, then dropped out, as he was more interested in eastern philosophy, fruitarian diets, and LSD than in the classes he took. He moved to a hippie commune in Oregon where his main activity was cultivating apples.
A few months later, Steve returned to California to look for a job. He was hired at the young video game maker Atari, and used his wages to make a trip to India with one of his college friends, in order to 'seek enlightenment'. He came back a little disillusioned and started to take interest in his friend Woz's new activities.

Apple's origins

The Jobses garage
Woz, whose interest in electronics had grown stronger, was regularly attending meetings of a group of early computer hobbyists called the Homebrew Computer Club. They were the real pioneers of personal computing, a collection of radio jammers, computer professionals and enlightened amateurs who gathered to show off their latest prowess in building their own personal computer or writing software. The club started to gain popularity after the Altair 8800 personal computer kit came out in 1975.
The knowledge that Woz gathered at the Homebrew meetings, as well as his exceptional talent, allowed him to build his own computer board — simply because he wanted a personal computer for himself. Steve Jobs took interest, and he quickly understood that his friend's brilliant invention could be sold to software hobbyists, who wanted to write software without the hassle of assembling a computer kit. Jobs convinced Wozniak to start a company for that purpose: Apple Computer was born on April 1, 1976.
The following months were spent assembling boards of Apple I computers in the Jobses' garage, and selling them to independent computer dealers in the area. However, Wozniak had started work on a much better computer, the Apple II — an expandable, much more powerful system that supported color graphics. Jobs and Wozniak knew deep down it could be hugely successful, and therefore Jobs started to seek venture capital. He eventually convinced former Intel executive turned business angel Mike Markkula to invest $250,000 in Apple, in January 1977. Markkula was a big believer in the personal computing revolution, and he said to the young founders that, thanks to the Apple II, their company could be one of the Fortune 500 in less than two years.

Apple II Forever

Although Markkula was a bit too optimistic about Apple's growth rate, he was right that the company quickly became an American success story. Because of its beautiful package, ease of use, and nifty features, the Apple II crushed most of its competition and its sales made the Apple founders millionaires. The biggest surge in sales came after the introduction of VisiCalc, the first commercially successful spreadsheet program: hundreds of thousands of Americans, whether they be accountants, small business owners, or just obsessed with money, bought Apple IIs to make calculations at home.
In the wake of Apple's success, its investors decided it was time to go public. The IPO took place in December 1980, only four years after the company was started. Steve Jobs's net worth increased to over $200 million, at age 25.
Apple's success attracted the attention of the computer giant IBM, which until then was still only selling mainframe computers to large companies. A crash project was started and in August 1981, the IBM PC entered the personal computer market. It was the biggest threat yet to Apple, whose reputation was being put into question after the flop of the Apple III in 1980. Most hopes rested on a business computer project, called the Lisa.

Lisa & Xerox PARC

Steve Jobs was a big believer in the Lisa computer initially. It was he who came up with the name. Indeed, in 1978, his ex-girlfriend from high school Chrisann Brennan gave birth to a little girl, who she named Lisa. Steve denied paternity, although it was ovious to everyone who knew him that he was the father, given the on-and-off relationship he still had with Chrisann at the time. Jobs refused to give any money to Chrisann, despite the millions he had accumulated at Apple. While in denial, he came up with the name Lisa for the new computer Apple was building…
The following year, a tour of the computer research lab Xerox PARC made a huge impression on him. The scientists who worked there had invented a number of breakthrough technologies that would mark the industry for the coming decades, including the graphical user interface (GUI) and the mouse, Ethernet, laser printing and object oriented programming. Jobs became obsessed with the GUI which was a lot easier to use than the command-line interfaces of the day, which required any PC user to learn a computer language. He insisted the Lisa had a GUI and a mouse, too.

Macintosh

However, because of his hot temper and his relative inexperience in technology or management, Steve Jobs was thrown out of the Lisa project. He felt absolutely crushed by this decision. As a revenge, he took over a small project called Macintosh, a personal computer that was supposed to be a cheap appliance, 'as easy to use as a toaster'. In 1981, Steve Jobs became head of the Macintosh project, and decided to make it a smaller and cheaper version of the Lisa, complete with a GUI of folders, icons and drop-down menus, and a mouse.
Photo by Norman Seef
The three years it took to develop Macintosh were some of the most productive and intense for Steve Jobs. He formed a small group of dedicated, young, brilliant engineers who stood fully behind his vision of a computer 'for the rest of us'. They saw themselves as 'pirates' against the rest of Apple, 'the Navy'. The team antagonized both the Apple II group and the Lisa group, because the Mac was competitive of both. Yet in 1983, after it became clear the Lisa was turning into another major flop for Apple, all of the company's hope started to rest on the Macintosh. Steve was supported in his mission by John Sculley, Apple's new CEO whom he hired in 1983 to help him run the company and groom him into a future chief executive.

Leaving Apple

On January 24 1984, after Apple had run a very memorable TV commercial for the SuperBowl ('1984'), Steve Jobs introduced Macintosh at the company's annual shareholders meeting. The product was launched in great fanfare and for the first few months, it was very successful.
Jobs and Sculley, 1984
However, by early 1985, sales were plummeting, but Steve Jobs refused to acknowledge it and continued to behave as if he had saved Apple. This created a lot of tension within the company, especially between Steve and the CEO, John Sculley, who used to be very close but now stopped talking to one another.
In May 1985, Steve Jobs started trying to convince some directors and top executives at Apple that Sculley should go. Instead, many of them talked to Sculley, who took the matter to the board of directors. The board sided with Sculley and a few days later, announced a reorganization of the company where Steve Jobs had no operational duties whatsoever — he was only to remain chairman of the board.
Steve was aghast: Apple was his life, and he was effectively kicked out of it. After four months spent traveling and trying out new ideas, he came back in September with a plan: he would start a new computer company aimed at higher education, with a small group of other ex-Apple employees. When Apple learned of the plan, they declared they would sue him as he was taking valuable information about the company to compete with it. As a result, Steve Jobs resigned in September 1985, and sold all but one of his Apple shares, in disgust. He went ahead with his plan anyway, and incorporated NeXT. Apple dropped its lawsuit a few months later.

The NeXT years

Steve aimed at the highest possible standards for his new NeXT machine: he wanted the best hardware, built in the world's most automated factory, and running the most advanced software possible. He decided that the computer's operating system, NeXTSTEP, would be based on UNIX, the most robust system in the world , used by the military and universities— but that it would also be as easy to use as a Macintosh,with its own GUI. NeXTSTEP would allow for object oriented programming, another breakthrough from Xerox PARC, that made writing software much faster and more reliably. These ambitious plans put off the release date of the computer — called the NeXT Cube — to October 1988.
Jobs unveils the NeXT Cube, 12 October 1988
When it came out, the NeXT Cube was indeed a great machine. But it didn't sell — it was late, and way too overpriced: universities has asked for a $3,000 computer, and Steve Jobs had built a $10,000 workstation. After two years of very low sales, NeXT launched the cheaper NeXT Station, and expanded its target to businesses, in addition to higher ed. It didn't work: the number of NeXT computers sold each month remained in the hundreds. The company was bleeding money and all its co-founders left one after the other, as well as its most prominent investor, Texan billionaire Ross Perot. By 1993, NeXT had to give up its entire hardware business to become a niche software company. Steve Jobs had failed, and he was devastated. He started focusing less on work, and more on his wife Laurene (who he married in 1991) and his newborn son, Reed.

Pixar

To understand how Steve Jobs got out of his nadir, let's go back eight years earlier, in late 1985. At the time, George Lucas, who was in the middle of an expensive divorce, was selling the computer graphics division of his Lucasfilm empire. Steve Jobs had millions in the bank, after having sold all his Apple stock, and was interested. In early 1986, he bought the small group of computer scientists, and incorporated it as Pixar. The founders of Pixar, Ed Catmull and Alvy Ray Smith, had gotten together in the late 1970s with a common vision of making films using computer animation only. But they also knew no computer was powerful enough at the time, and they would have to hold out for a couple decades before their dream could materialize.
Tin Toy
For the first five years of Pixar, Steve Jobs set a goal for the company to sell high-end computer graphics workstations for institutions, such as hospitals or even the army. The animations group led by John Lasseter was very small at the time, and only survived because it provided good publicity for the power of the Pixar rendering software. Steve Jobs understood this when the studio won an Academy Award for its short movie 'Tin Toy' in 1989. However, just like NeXT's, sales of Pixar hardware were microscopic, and the company went software-only in 1990.
Pixar then became a software company, developing the RenderMan 3D rendering software. Its animation business was kept alive because it was the only one that brought some cash in, with various 3D TV commercials for consumer brands. However a decisive contract changed everything: in 1991, Disney signed with Pixar for making a full-feature computer-animated movie. The script had to be fully approved by both parties, and the very hands-on head of Disney animation Jeffrey Katzenberg halted the production several times out of creative disagreements with John Lasseter and his team. But in 1995, the movie was finally starting to take form, and Steve Jobs became increasingly enthused by it.
Steve as Woodie
Although he had used his personal money to fund Pixar for nine years, Jobs had never been implicated that much in the company, which was always more of a 'hobby' to him compared to NeXT. But by 1995, NeXT had more or less tanked, whereas Pixar was obviously going to benefit widely from the Disney marketing machine and make a hit with Toy Story. Steve understood this new momentum full well: he planned to take Pixar public the week following the release of the movie, in November 1995. He was right, and Toy Story's box-office success was only surpassed by the Pixar stock's success on Wall Street. Steve Jobs, who owned 80% of the company, saw his net worth rise to over $1.5 billion — five times the money he had ever made at Apple in the 1980s!

Back to Apple

Business wasn't all sunshine and roses at Apple. In the decade following Steve's departure, the computer maker had milked all the cash it could from the Macintosh and its successors, surfing on the wave of the desktop publishing revolution that the Mac and the laser printer had made possible. But in 1995, after Microsoft had released Windows 95, which was a pale but working copy of the Mac OS, sales of Macintosh computers started plummeting.
A new CEO, Gil Amelio, arrived in early 1996 to save the company. He cut costs, got rid of a third of the workforce, and decided that instead of writing a new, modern operating system from scratch to compete with Window, it was better for Apple to acquire one. Eventually, Amelio chose to buy NeXTSTEP, NeXT's operating system — and Steve Jobs convinced him to buy the whole company, for a whopping $400 million. The deal was made in December 1996: Steve Jobs was back at the company he founded.
Steve Jobs and Gil Amelio, December 1996
The Amelio-Jobs cooperation didn't last long, though: Apple lost $700 million in the first quarter of 1997, and the board decided to get rid of its CEO. Jobs effectively organized a board coup with the complicity of his billionaire friend Larry Ellison, and after a tenure that lasted exactly 500 days, Amelio was gone. In August 1997, Jobs took the stage at Macworld Boston to explain his plan for Apple: he had gotten rid of the old board of directors, and made a deal with Microsoft to settle patent disputes and invest $150 million in the struggling Silicon Valley icon. One month later, on September 16, 1997, Jobs accepted to become Apple's interim CEO.

For the loser now will be later to win

The few months after Steve Jobs came back at Apple were among the hardest-working in his life. He later told his biographer Walter Isaacson that he was so exhausted, he couldn't speak when he came home at night (remember he was also running a thriving Pixar simultaneously). He reviewed every team at Apple and asked them to justify why they were important to the future of the company. If they couldn't, their product would get canceled, and there was a high probability they'd have to leave, too. Jobs also brought with him his executive team from NeXT, and installed them in key positions.
iMac introduction, May 1998
Critics started to believe in Steve Jobs's ability to run Apple when he unveiled his first great product, the iMac. Introduced in May 1998, it was Apple's first truly innovative product since the original Macintosh of 1984. Its translucent design blew away the whole PC industry, which had failed to produce anything but black or beige boxes for over a decade. Moreover, it was a hot seller, and played a key role in bringing back tons of developers to the Mac platform. Design innovations continued throughout 1998 and 1999 with the colored iMacs and the iBook, Apple's consumer notebook. After three years in charge, Steve Jobs had brought Apple back to its status of cool tech icon.
At Macworld in January 2000, Steve Jobs made two significant announcements: first, he demoed Aqua, the graphics-intensive user interface that Apple would use in its next-generation operating system derived from NeXTSTEP, Mac OS X. Second, he announced he had accepted the Apple board's offer, and became the company's CEO, dropping the 'interim' from his title. It was not an obvious choice because he remained CEO of Pixar, too. Mac OS X had not shipped yet, though, and would take another year to ship.
The simple fact that such a massive OS transition happened is a technical feat in itself. The Mac OS X team worked very hard and released six major version of the system every year or so, between 2001 and 2007, each time with more stability, rapidity, and features. Although Steve Jobs buried Mac OS 9 on stage in 2002, most observers acknowledge that the transition from the old Mac OS to OS X was really finished only in 2005, with the release of Mac OS X 10.4 Tiger. The continuous improvement of Mac OS X and the powerful core technologies and development tools it provided proved key in the Digital Hub strategy that Steve Jobs described in January 2001.

The Digital Hub strategy

Once Apple had been resurrected by the iMac, Steve Jobs started focusing on ways to make the company's shrinking marketshare (around 5% of PCs) grow. He decided to use Apple's unique knowledge of making both the hardware and the software to do just that: not only would Macs be very powerful and attractive machines, but they would also run software that no Windows PCs could. His first move was to bet on what he called 'desktop video', the ability to shoot and edit personal movies on your Mac. He was convinced that desktop video would be as big a deal as desktop publishing had been in the 1980s, and in 1999, he introduced the iMac DV and a digital movie editing software, iMovie, to pioneer that concept.
The iMac DV was a hit, but desktop video failed to catch on as Jobs had hoped. After a much introspection, in 2000, the Apple executive team came up with a new paradigm for the Mac that would set the company's destinies for the coming decade. They took the idea of desktop video and decided to expand it to the other consumer digital devices that were rapidly becoming mainstream at the time. Apple would write software for the Mac to edit and store all the new digital content that consumers created — and these apps would be so powerful, delightful and easy to use, that they would entice PC users to switch to the Mac. The Digital Hub strategy was born. Steve Jobs explained it to the Apple community at Macworld in January 2001, the same day he unveiled the 2nd and 3rd of the iApps: iDVD, to shares iMovies with family and friends on DVDs; and iTunes, a digital jukebox software. Other iApps would follow: iPhoto in 2002, GarageBand in 2004, and iWeb in 2006.

2001: An Apple Odyssey

In many ways, the juggernaut that Apple became was shaped by very smart decisions that Jobs and his executive team took in the crucial 2000-2001 timeframe. We've talked of Mac OS X and the Digital Hub strategy, a crucial product and a crucial strategy that were both unveiled in January 2001.
A third key decision was taken in 2000 and unveiled in mid-2001: that of creating a fully-owned retail channel, the famous Apple retail stores. Although it is easy to approve of this strategy in retrospect, it was far from an obvious choice back in May 2001, when the first two retail stores were inaugurated. PC maker Gateway was shutting down its own retail stores one after the other, and the analysts consensus at the time was that niche player Apple would burn precious money in this economic downturn on a foolish and dated idea. On the other hand, Steve Jobs explained that only in an environment fully controlled by Apple, with Apple-trained staff and only Apple-compatible products, could the superiority of Macs be fully appreciated by consumers.
iPod, October 2001
Finally, it was in 2000 that Jobs started realizing his mistake of betting only on digital movies, and reoriented the company's efforts to another media: music. Digital music file-sharing service Napster was at the peak of its popularity, and all the young people were not spending their time shooting movies, but rather downloading and listening to MP3 music files. iTunes was born out of that realization, but there was a problem: although there were great digital camcorders to run in conjunction with iMovie, and awesome digital cameras too, digital music players mostly sucked — not to mention their universal ugliness.
That's why, in March 2001, Steve Jobs started a crash development program to develop an Apple-branded MP3 player before that year's holiday season: the iPod was born. On October 23, 2001, he introduced this cute white digital device to a small group of journalists in the company's campus auditorium. The tagline was '1,000 songs in your pocket', and there was great emphasis on its symbiosis with the iTunes app. But no one in the room, Jobs included, had any clue how important it would turn out to the company's future.

iPod nation

The first digital music player that people loved, iPod was a commercial success from the day it debuted. It was released, of course, as Mac-compatible only, because its goal, just like iMovie or iDVD, was to help sales of Macs. But it came at a time when a lot of people needed a good MP3 player, and despite its rather high price tag, a lot of PC users ended up buying it too, hacking it so they could use it on their machines. This had Steve Jobs and his team think a great deal: should they keep making a Mac-only iPod, or should they open it to Windows, too? Although Jobs was opposed to the latter idea, he eventually relented, and the first Windows iPods were introduced in July 2002 at Macworld New York.
However, it was soon becoming clear that iPod benefited from music piracy, and that its sales could go even higher if there was a legal way to download music. Steve Jobs didn't wait for the music industry to reinvent itself. He went to all record labels to negotiate landmark deals that would lead to the introduction of the iTunes Music Store in April 2003. Ironically, one of the arguments he used was that the risk to music labels was quite low, because of the Mac's small market share (iTunes was still Mac-only). The first compelling legal alternative to illegal music file-sharing, the iTunes Store was an instant success, selling one million songs in its first week. It not only helped the sales of iPods, but it eventually reshaped the whole music industry. It was introduced to Windows as well six months later, in October 2003.
Despite this great success, Apple didn't rest on its laurels. In January 2004, it introduced the iPod mini, a more compact version of iPod that sold at $249, only $50 less than the full featured iPod. It is really after iPod mini came out that iPod became the cultural icon it is now known as. The phrase 'Walkman of the digital age' became commonplace to describe it, and in July 2004, Steven Levy of Newsweek wrote an emblematic cover story entitled 'iPod nation'. The iPod adventure was far from over, since Apple introduced the $99 iPod shuffle and the 'impossibly small' iPod nano in 2005, and the iPod video in 2006. By that time, iPod had become synonymous with music player, and the iTunes Store had sold over one billion songs.
Steve posing with iPod minis, 2004
Although iPod changed the music industry and the way everybody listen to music, the most important change it carried was probably that of Apple. The wild success of iPod proved to all the company's employees, starting with Jobs himself, that they were right to strive for perfection and ease of use — unlike the Mac, which still didn't make it past the 5% marketshare, iPod garnered Microsoft-like numbers of 80% of sales of MP3 players. It was iPod that revealed the future of Apple, not only as a PC manufacturer, but as a consumer electronics powerhouse. It was also iPod that broadened the company's expertise in the manufacturing, logistics and distribution of a mainstream digital device in gigantic proportions. Finally, it was iPod which, through the crowds it attracted to the company's retail stores, finally helped the Mac business of Apple, whose growth rate outpaced that of Windows PCs starting in 2005.

When Pixar met Disney

Steve Jobs and Michael Eisner, 1995
iPod also played an indirect role in shaping the future of Steve's 'other' company, Pixar. After having released hit after hit (A Bug's Life (1998), Toy Story 2 (1999), Monsters Inc. (2001) and Finding Nemo (2003)), the animation studio had decided to let go of its distribution deal with Disney, mainly because of increasing tensions between Steve Jobs and Disney CEO Michael Eisner. Steve Jobs openly said he would not make another deal with the Magic Kingdom company until Eisner was out. Turns out his opinion was shared by many an executive at Disney — including Walt's own nephew, Roy Disney, who started a public campaign to oust the company's CEO in late 2003. Th led to the nomination of Bob Iger as new CEO in September 2005.
Ed Catmull, Steve Jobs, Disney CEO Bob Iger and John Lasseter on Jan 24, 2006
Rumor has it that one of the first phone calls Iger made after he became CEO was to Pixar CEO Steve Jobs. He was willing to show his good will in ending the Pixar-Disney dispute. Steve Jobs took the opportunity to pitch him his new Apple plan. He was going to introduced an iPod with video capabilities soon, and he wanted a movie store to go along with it. Iger accepted, and both men appeared on stage in October to announce that Disney would sell music videos and TV shows on iTunes. The audience of journalists was pleasantly surprised to see the CEO of Disney appear so friendly with Steve Jobs, and suspected there would soon be news on the Pixar side.
Indeed, on January 24, 2006, Disney announced its friendly acquisition of Pixar, putting $7.4 billion in stock on the table. Jobs became a Disney board member and its largest individual shareholder (owning 7% of the company's stock), while Pixar executives Ed Catmull and John Lasseter were both given critical roles in the new studio.

Momentum

Meanwhile, Apple was seeing unprecedented success in all its businesses, not only iPod and iTunes. The retail stores were hugely popular, and a milestone was reached when Steve Jobs inaugurated the impressive 5th Avenue store in New York CIty, a glass cube facing Central Park. As for the Mac, it was gaining momentum on the market, benefiting from both the aura of the iPod, and the switch to Intel.
Indeed, in June 2005, at WWDC, Jobs made a surprise announcement that after over a decade using the PowerPC microprocessor architecture in Macs, Apple would start using the more power-efficient Intel platform. In the late 1990s, Apple had run several ads to make fun of Intel's Pentium processors, which were commonplace in the Windows world. As a matter of fact, the expression 'Wintel machines' (Windows + Intel) was often used to describe PCs. That move to Intel was thus pretty bold, but in the long run turned out to be another wise decision. Not only did it make Macs more efficient, and pave the way for the super slim MacBook Air notebooks, but it also opened up a whole new set of customers of Apple. Intel Macs could run both Mac OS X (and its UNIX terminal) and Windows, and became the platform of choice for the majority of developers. All Macs were running Intel less than a year after the announcement.
Steve Jobs and Intel CEO Paul Otellini at Macworld 2006

Apple Inc.

iPod made Steve Jobs realize that Apple could become the greatest consumer electronics company on the planet. Around 2003, he started a secret project to develop a tablet. But in 2004-2005, he realized that the technology that this group had developed, including a revolutionary touch-screen technology, could be used in a phone rather than a tablet. After two more years of development, including a harsh internal competition to prove that it was possible to make Mac OS X run on the phone, iPhone was introduced at Macworld on January 9, 2007. This keynote is often considered the best and most memorable of all of Steve Jobs's career.
iPhone was not only a breakthrough digital convergence device ("an iPod, a phone, and an Internet communicator" all in one), it was also a force of disruption of the traditional phone business. Just like for the iTunes Store, Steve Jobs had negotiated landmark deals with wireless carrier AT&T before he introduced iPhone — without ever showing it to them! In exchange for exclusivity, the carrier would pay Apple a share of all their iPhone subscription revenues. And of course, AT&T could not put any software on the iPhone, and no logo either. This was an inversion of the traditional master-slave relationship that carriers entertained with phone manufacturers. In the long run, it really put the phone industry upside down.
Unlike iPod, all of Apple understood that iPhone would be a successful and rules-changing device, starting with their own company. That's why Steve Jobs announced that its name would change from Apple Computer Inc. to Apple Inc. Macs still mattered, but accounted for a minority of Apple's revenues already, and this decline would not stop any time soon. Apple had become the most prominent digital device company.
The original iPhone was successful already: despite its $399 price tag, Apple sold 6 million of them during its existence. But sales really started to skyrocket in 2008, after Apple introduced the cheaper iPhone 3G (at a subsidized $199 price) and the App Store. Just like the Windows-compatible iPod, Steve Jobs was originally opposed to letting third-party software on the iPhone. But the demand was so high that he eventually relented, and introduced the iPhone SDK and the App Store in March 2008.
It is impossible to overestimate the impact of the iPhone App Store, which ushered in a new era in mobile software. Thousands of developers started writing apps for the iPhone platform, which became a competitive advantage for Apple that no other company has been able to catch up with to this day. Apple proudly showed off this rich choice of software in its TV ad campaign 'There's an app for that' that ran for over two years.

Health concerns

Unfortunately, while he had never been so successful professionally, Steve Jobs had to start fighting cancer with renewed intensity.
In late 2003, he had been diagnosed with pancreatic cancer of a rare kind, that could potentially be cured by surgery. However, against everyone's advice, he refused to have the surgery for nine long months. Instead, true to the ideals of his youth, he tried alternative diets and treatments, including acupuncture and seeing a psychic. Only in July 2004 did he agree to have the surgery. He looked healthy for the next five years, and spoke publicly of being 'cured' of cancer at his famous Stanford speech in 2005.
Yet at the WWDC keynote in June 2008, few observers failed to notice how thin he appeared on stage, and concerns about his health started popping up again. They became increasingly frequent until December 2008, when Apple made a shocking announcement that Jobs would not be the keynote speaker at Macworld 2009, and that he was taking a medical leave of absence for six months. Although he publicly denied it, the truth was of course that his cancer had come back. He was actually weeks away from death when he received a liver transplant in April 2009. But he came back to Apple, as planned, in late summer 2009, healthier though still very frail in appearance. He was eager to bring the finishing touches to a new project very dear to his heart.

Ushering in the Post-PC era

WWDC 2011
The iPhone had spun off the idea for a tablet device back in 2005, and it was time to restart that project, which of course led to the introduction of iPad. Although some speculated it would run Mac OS X, it was decided that iPad would in fact run the same operating system as iPhone, now called iOS. It would therefore benefit from the rich variety of apps already present in the iPhone App Store.
Although iPad was welcomed by mixed reviews when it was introduced in January 2010 (some dubbed it a "larger iPod touch"), it was always clear to Steve Jobs that it was 'the biggest thing [he'd] ever done' — the ultimate post-PC device, an eventual replacement of PCs for the average user. He laid out his vision clearly at the D8 conference in May 2010, where he compared PCs to trucks, which still existed after cars were invented but were only for professional, niche use. This perspective on iPad was reiterated in a series of TV commercials where the narrator, the 'Apple voice', explained how revolutionary iPad was and how the revolution had 'only just begun'.
Unfortunately, Steve Jobs' health, which had seem to recover throughout 2010, started declining again. In January 2011, he announced he was taking a new medical leave of absence, this time without saying when it would end. Everybody started talking about his upcoming departure. However, he deemed iPad and iOS so important that he still made two major public presentations at Apple event. The first one was the introduction of iPad 2 in March 2011, and the second one was WWDC, in June 2011, where he introduced iCloud.
In many ways, the iCloud announcement was of similar importance as the Digital Hub Strategy introduction ten years before. It was not only a product, but a master plan to get consumers to adopt iOS devices and lock them into the Apple ecosystem. The iCloud introduced in 2011, which allowed users to sync email, documents, and media across their Macs, iPhones, iPod touches, iPads and Apple TVs, was only the first step in that direction. It was crucial to Steve Jobs who clearly put iOS as the most important part of Apple and the key to its future.

Building his legacy

The resurgence of Steve's cancer was a painful reminder that it was time to 'put his affairs in order' before his passing — and he did.
He made sure that Apple was ready to operate without him: in late 2008, he hired the dean of the Yale School of Management to create 'Apple University', a sort of internal business track to groom future Apple executives by exposing them to the Apple ways of doing business, through actual case studies in the history of the company. He also consolidated his executive team and agreed with the board that his natural successor would be his second in command, COO Tim Cook. Finally, at his last public appearance in June 2011, he unveiled his plans for the future Apple campus in Cupertino, a huge spaceship-sized building in the shape of a perfect circle. All of this was in place when, because of his increasingly deteriorating health, he resigned as Apple CEO on August 24, 2011.
Jobs also prepared his personal legacy. In 2009, he finally started giving interviews to journalist Walter Isaacson to prepare for his first and only authorized biography, giving him his perspective on his life and career. He also spent his last days designing a boat for his family on which he hoped to travel the world. Unfortunately, death took him too soon, and he died peacefully at home on October 5, 2011, surrounded by his family — the day following the introduction of the iPhone 4S, an Apple event that he watched from his deathbed.
The future Apple spaceship campus