DIGIT-ARC read-only archive · snapshot: July 23, 2026

The Algorithms thread

15 posts · originally from https://geek.digit.in/community/threads/the-algorithms-thread.68062/

Abhishek Dwivedi
Abhishek Dwivedi Original post #1
Sep 13, 2007 at 3:55 PM
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 at 7:18 PM
Programing Language- Any language
Algorithm required-VBR(Variable bit rate) for mp3
Program(if made)-LAME
Quiz_Master
Sep 14, 2007 at 2:59 AM
Programming Language : C/C++
Algorithm Required : To sort a list of names in alphabeticle order.
Projjwal
Sep 14, 2007 at 10:33 AM
^^@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 at 11:18 AM
Hey Projjval .. Thanks... Now I can complete my homework :D
Abhishek Dwivedi
Sep 14, 2007 at 4:09 PM
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 at 8:54 PM
Programming Language: C# / .NET 3.0 / Vista

What it Does : Outputs a String as A Voice Message

Code:
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 at 7:30 AM
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 at 11:50 AM
^^
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.
M
mehulved #10
Sep 16, 2007 at 8:44 PM
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
Projjwal #11
Sep 16, 2007 at 8:57 PM
^^ pls explain it ..
M
mehulved #12
Sep 18, 2007 at 3:43 PM
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 at 7:29 PM
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.

----------------------------------------------
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.
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
Projjwal #14
Sep 18, 2007 at 11:46 PM
Yea.....sending through system() is true. but wht about the output of the cmd
window in my application window?
Abhishek Dwivedi
Oct 30, 2007 at 7:35 PM
congrats guys...v now have a whole new programing section....cool uh?