October 2009
M T W T F S S
    Nov »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Categories

  • [+]ASP.NET (7) 
  • [+]C# (87) 
  • [—]C++ (13) 
  • [+]Delphi (20) 
  • [+]JavaScript (24) 
  • [+]Regular Expressions (7) 
  • [+]SQL (13) 
  • [+]VB (100) 
  • [+]VB.NET (4) 

Online

Users: 6 Guests
  • Loading...


    Loading...

    Login






    Register | Lost password?

    Register





    A password will be mailed to you.
    Log in | Lost password?

    Retrieve password





    A confirmation mail will be sent to your e-mail address.
    Log in | Register
  • String Recognition 2

    /* String Recognition */
    
    #include<stdio.h>
    #include<conio.h>
    #include<iostream.h>
    #define SIZE_OF_STACK 30 //Number of slots in Stack
    
    char alphabet[50];
    int count=0;
    class stack
    {
     private:
    	char slot[SIZE_OF_STACK];
    	int TOP;
     public:
    	stack()
    	{
    	 TOP=-1;
    	}
    
    	int PUSH(char item)
    	{
    		 if(TOP==SIZE_OF_STACK-1)
    		 {
    			return 0; // Push Operation Unsuccessful
    		 }
    		 else
    		 {
    			  TOP++;
    			  slot[TOP]=item;
    			return 1; // Push Operation Successful
    		 }
    	}
    
    	char POP(void)
    	{
    		if(TOP==-1)
    		{
    			return -1;
    		}
    		else
    		{
    		 TOP--;
    		 return slot[TOP+1];
    		}
    	}
    
    	void PEEP(int slot_number)
    	{
    		 slot_number=slot_number-1;
    
    		 if(slot_number>TOP&&slot_number<=SIZE_OF_STACK-1)
    		 {
    		  cout<<endl<<"ERROR : Item does not exist ! Last item is at Slot "<<TOP+1;
    		 }
    		 else if(slot_number<0)
    		 {
    		  cout<<endl<<"ERROR : Enter a valid Slot Number !";
    		 }
    		 else if(slot_number>SIZE_OF_STACK-1)
    		 {
    		 cout<<endl<<"ERROR : Slot number beyond bounds of stack ! Size of Stack is "<<SIZE_OF_STACK;
    		 }
    		 else
    		 {
    		  cout<<slot[slot_number];
    		 }
    	}
    
    	int get_top()
    	{
    	 return TOP;
    	}
    };
    
    void main()
    {
     clrscr();
     stack s;
     int no_of_alphabets=0;
     int check_alphabet(char);
     char next_alphabet(void);
     char temp;
     do
     {
    	 cout<<"How many alphabets does the language contain? : ";
    	 cin>>no_of_alphabets;
    	 if(no_of_alphabets<=0)
    	 {
    		cout<<endl<<"ERROR : Enter a valid number (>0) !"<<endl<<endl;
    	 }
     }while(no_of_alphabets<=0);
    
     for(int i=0;i<no_of_alphabets;i++)
     {
    	cout<<endl<<"Alphabet "<<i+1<<" : ";
    	temp=getch();
    	putchar(temp);
    	if(check_alphabet(temp)==0)
    	{
    		cout<<"   ERROR : Character already exists in the language !";
    		i--;
    	}
    	else
    	{
    		alphabet[i]=temp;
    		count++;
    	}
     }
     alphabet[i]='\0';
    
     getch();
    
    }
    
    int check_alphabet(char x)
    {
     for(int i=0;i<count;i++)
     {
    	if(x==alphabet[i])
    	{
    		return 0; // Character Repeated
    	}
     }
     return 1;
    }
    
    char next_alphabet(void)
    {
     static int number=0;
     number++;
     return alphabet[number];
    }
    
    Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • Digg
    • del.icio.us
    • Bloglines
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Technorati
    • TwitThis
    • Webnews

    Leave a Reply

     

     

     

    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

    Spam Protection by WP-SpamFree Plugin