mahima
BAN USERMy searching algorithm was of order o(n^3)
i searchd for each letter of string 'microsoft' in 2-D string
and wherever i found that charachter i replaced it with '1' and incremented the loop for the string to find next letter.
then i counted the number of '1' in the 2-D String
if it equals the length of 'microsoft'
this means string found
else
not found...fortunately my algorithm worked in c++
I wrote this..wat do u say ppl?
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#define SIZE 20
class stack
{ public :
int arr[SIZE];
int data;
int top;
stack()
{
top=-1;
}
void pop(int &top);
int push(int ele);
void display();
};
void stack :: pop(int &top)
{
int tmp;
if(top==-1)
cout<<"Deletion not possible"<<endl;
else
{
tmp=arr[top];
top=top-1;
cout<<"The element deleted is "<<tmp<<endl;
}
}
int stack:: push(int ele)
{
if(top==SIZE-1)
cout<<"Insertion cannot be performed"<<endl;
else
{
top=top+1;
arr[top]=ele;
cout<<"Element inserted"<<endl;
}
return top;
}
void stack :: display()
{ int i;
if(top==-1)
cout<<"The stack you have called is empty"<<endl;
else
{
cout<<"^"<<endl;
for(i=top;i>=0;i--)
cout<<arr[i]<<endl;
cout<<"-"<<endl;
}
}
void main()
{ clrscr();
stack s1;
stack s2;
int topp,topp1;
topp=s1.push(2);
topp=s1.push(3);
topp=s1.push(4);
s1.display();
for(int i=topp;i>=0;i--)
{
topp1=s2.push(s1.arr[i]);
}
s2.display();
s2.pop(topp1);
s2.pop(topp1);
s2.pop(topp1);
getch();
}
while(str[l]!='\0')
- mahima September 13, 2013{
for(int i=0;i<n;i++)
{
for(int j=0;j<=n-i-1;j++)
cout<<" ";
for(j=0;j<=i;j++)
{
cout<<str[l++]<<" ";
}
cout<<"\n";
}}}
this will print your name in pascal triangle!