1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?
_
_________________________________________________________________
1.2 Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)
_
_________________________________________________________________
1.3 Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is not.
FOLLOW UP
Write the test cases for this method.
_
_________________________________________________________________
1.4 Write a method to decide if two strings are anagrams or not.
_
_________________________________________________________________
1.5 Write a method to replace all spaces in a string with ‘%20’.
_
________________________________________________________________
1.6 Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?
_
________________________________________________________________
1.7 Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.
_
________________________________________________________________
1.8 Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring (i.e., “waterbottle” is a rotation of “erbottlewat”).
how to sort integers using stack.
plssssss provide a solution for it...pls
Dear,
What you want to ask exactly? Give us the clear details.
Because if you are asking for simple sorting of numbers which are in stack, it is easy to do.
So explain a little bit dear.
Sir their are n numbers(integers) in stack,we need to sort them...
pls give solution...
and one more we need sort characters,,like if i give BADCE
out put will be ABCDE...
i wrote a solution like this its working..but if give BaDcE..its not working pls help out,,i need solution plsssss..give me code...
my logic(if (a[i]>a[i+1](swap ()));....
For your first question, I would say :-
it depends how you have implemented the stack. i.e it is an array implementation or linked list implementation . Sorting in both the cases will be different concepts.
And for your second question :-
Obviously you code will not work for BaDcE. Because
when we check if(b>a)
then ascii value of b=98 and a=97 are checked by compiler i.e if(98 > 97)
and what are you trying to compare
if(B >a )
it will never be true because ascii value of 'B' is '66' and that of 'a' is 97
and now you judge your code. Is is possible that if(66 > 97) , not possible.
So try doing this. take another array and store every element in the upper or lower case and then perform your task
thank u sooo much....
but give me code for array implementation ,n numbers(integers) in stack,we need to sort them...
pls give solution...i need proggarm..sir..plsss
You can add me @ engineerhiteshahuja@gmail.com
#include
#include
void main()
{ int top=-1; // represents underflow condition
int s[10];
printf("enter array elements");
for(i=0;i<5;i++)
{ top=top+1;
scanf("%d",&a[top]);
}
int temp;
temp=top;
for(i=0;ia[j])
swap();// write code here
}
// now print it.
// see while array implementation of stack, there is no difference b/w sorting an array or sorting a stack
}
}
Admin I here is prog for sorting integers using stack but when i complie,,,their are lots of error..pls help...correct and give runnable code..plssssssss
#include
using namespace std;
struct node
{
int data;
node *next;
node()
{
next=NULL;
}
node(int x)
{
data=x;
next=NULL;
}
// ~node()
// {
// delete next[];
// }
};
struct stack
{
node *head;
stack()
{
head=NULL;
}
void push(int x)
{
node *n=new node(x);
if(head==NULL)
{
head=n;
}
else
{
n->next=head;
head=n;
}
}
int pop()
{
node *temp=head;
if(head->next!=NULL)
head=head->next;
else
head=NULL;
return temp->data;
}
bool IsEmpty()
{
if(head==NULL)
return true;
else
return false;
}
int top()
{
if(head!=NULL)
{
return head->data;
}
}
void print()
{
node *temp=head;
while(temp!=NULL)
{
cout<data<<" ";
temp=temp->next;
}
cout<<endl;
}
};
void sort_stack(stack &s)
{
stack A,B;
while(!s.IsEmpty())
{
int tmp=s.pop();
if(A.IsEmpty())
{
A.push(tmp);
continue;
}
if(A.top()<tmp)
{
int mark=0;
while(!A.IsEmpty() && A.top() <tmp)
{
mark=1;
B.push(A.pop());
}
if(mark==1)
{
mark=0;
A.push(tmp);
}
while(!B.IsEmpty())
{
A.push(B.pop());
}
}
else
{
A.push(tmp);
}
}
while(!A.IsEmpty())
{
s.push(A.pop());
}
}
void main()
{
stack s;
s.push(15);
s.push(9);
s.push(2);
s.push(7);
s.push(3);
s.push(11);
s.print();
sort_stack(s);
s.print();
}
and pls explain this sorting method..only