# The Algorithms thread



## Abhishek Dwivedi (Sep 13, 2007)

This thread is for sharing and asking the basic Algorithms related to any Programing language.

Way of Asking:

Programing Language-
Algorithm required-
Program(if made)-
Other Information(if required)-


Important: Users Asking for the Algorithms should try Google search first before posting.

Hope this will help a lot of Young Students and others who are learning the programing methodology


----------



## Projjwal (Sep 13, 2007)

Programing Language- Any language
Algorithm required-VBR(Variable bit rate) for mp3
Program(if made)-LAME


----------



## Quiz_Master (Sep 14, 2007)

Programming Language : C/C++
Algorithm Required : To sort a list of names in alphabeticle order.


----------



## Projjwal (Sep 14, 2007)

^^@Quiz_Master
-----------------------------------------------------
     #include <stdlib.h>
     #include <stdio.h>
     #include <string.h>

     /* Define an array of critters to sort. */

     struct critter
       {
         const char *name;
         const char *species;
       };

     struct critter muppets[] =
       {
         {"Kermit", "frog"},
         {"Piggy", "pig"},
         {"Gonzo", "whatever"},
         {"Fozzie", "bear"},
         {"Sam", "eagle"},
         {"Robin", "frog"},
         {"Animal", "animal"},
         {"Camilla", "chicken"},
         {"Sweetums", "monster"},
         {"Dr. Strangepork", "pig"},
         {"Link Hogthrob", "pig"},
         {"Zoot", "human"},
         {"Dr. Bunsen Honeydew", "human"},
         {"Beaker", "human"},
         {"Swedish Chef", "human"}
       };

     int count = sizeof (muppets) / sizeof (struct critter);



     /* This is the comparison function used for sorting and searching. */

     int
     critter_cmp (const struct critter *c1, const struct critter *c2)
     {
       return strcmp (c1->name, c2->name);
     }


     /* Print information about a critter. */

     void
     print_critter (const struct critter *c)
     {
       printf ("%s, the %s\n", c->name, c->species);
     }


     /* Do the lookup into the sorted array. */

     void
     find_critter (const char *name)
     {
       struct critter target, *result;
       target.name = name;
       result = bsearch (&target, muppets, count, sizeof (struct critter),
                         critter_cmp);
       if (result)
         print_critter (result);
       else
         printf ("Couldn't find %s.\n", name);
     }

     /* Main program. */

     int
     main (void)
     {
       int i;

       for (i = 0; i < count; i++)
         print_critter (&muppets_);
       printf ("\n");

       qsort (muppets, count, sizeof (struct critter), critter_cmp);

       for (i = 0; i < count; i++)
         print_critter (&muppets);
       printf ("\n");

       find_critter ("Kermit");
       find_critter ("Gonzo");
       find_critter ("Janice");

       return 0;
     }
---------------------------------------
The output from this program looks like:
---------------------------------------
     Kermit, the frog
     Piggy, the pig
     Gonzo, the whatever
     Fozzie, the bear
     Sam, the eagle
     Robin, the frog
     Animal, the animal
     Camilla, the chicken
     Sweetums, the monster
     Dr. Strangepork, the pig
     Link Hogthrob, the pig
     Zoot, the human
     Dr. Bunsen Honeydew, the human
     Beaker, the human
     Swedish Chef, the human

     Animal, the animal
     Beaker, the human
     Camilla, the chicken
     Dr. Bunsen Honeydew, the human
     Dr. Strangepork, the pig
     Fozzie, the bear
     Gonzo, the whatever
     Kermit, the frog
     Link Hogthrob, the pig
     Piggy, the pig
     Robin, the frog
     Sam, the eagle
     Swedish Chef, the human
     Sweetums, the monster
     Zoot, the human

     Kermit, the frog
     Gonzo, the whatever
     Couldn't find Janice.
------------------------------------------
Source:*www.gnu.org/software/libc/manual/html_node/Search_002fSort-Example.html_


----------



## Quiz_Master (Sep 14, 2007)

Hey Projjval .. Thanks... Now I can complete my homework


----------



## Abhishek Dwivedi (Sep 14, 2007)

Programing Language : C++
Algorithms Required: A program to corupt the HDD
Other Information: I've heard its a 3 line program that can destroy the HDD.


----------



## Zeeshan Quireshi (Sep 14, 2007)

Programming Language: *C# / .NET 3.0 / Vista*

What it Does : *Outputs a String as A Voice Message*


```
using System;
using System.Speech.Synthesis;

namespace HelloSpeechSynthesis
{
    class Program
    {
        static void Main(string[] args)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.SpeakText("Hello, world!");
        }
    }
}
```


----------



## QwertyManiac (Sep 15, 2007)

Projjwal said:
			
		

> Programing Language- Any language
> Algorithm required-VBR(Variable bit rate) for mp3
> Program(if made)-LAME


Wont running LAME with the parameter *-v* do it? You can resample the bitrate to 64, 128 etc along too. Or did I not understand what you were asking ...


----------



## Projjwal (Sep 16, 2007)

^^
Yea I want a programming code in any language which convert normal mp3 to VBR mp3 just like LAME's -v option.
In other word de algo to convert normal mp3 to VBR mp3.

----------------------------------------------
Programing Language-C,C++
Algorithm required-A program which support all the command of cmd 
Program(if made)-I want to access all the command of cmd throug my application
As example if i type cd <directory_name> in that application it automatically create a directory with the name just like cmd.
I did it in VB6 but that logic not applied on c or c++ pls help.


----------



## mehulved (Sep 16, 2007)

Projjwal said:
			
		

> As example if i type cd <directory_name> in that application it automatically create a directory with the name just like cmd.
> I did it in VB6 but that logic not applied on c or c++ pls help.


I know that vim can do similar sort of thing, atleast on *nix. So, maybe you can check out the win32 port of vim if it has something similar and if it can help you.


----------



## Projjwal (Sep 16, 2007)

^^ pls explain it ..


----------



## mehulved (Sep 18, 2007)

vim is a text editor. Check the source code of win32 port of vim, you might be able to find what you need. See *www.vim.org/download.php#pc


----------



## Zeeshan Quireshi (Sep 18, 2007)

Projjwal said:
			
		

> ^^
> Yea I want a programming code in any language which convert normal mp3 to VBR mp3 just like LAME's -v option.
> In other word de algo to convert normal mp3 to VBR mp3.
> 
> ...


well u can do this simply by taking the input as a string and then passing the command onto the system using the system() function .


----------



## Projjwal (Sep 18, 2007)

Yea.....sending through system() is true. but wht about  the output of the cmd 
window  in my application window?


----------



## Abhishek Dwivedi (Oct 30, 2007)

congrats guys...v now have a whole new programing section....cool uh?


----------

