Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, 11 December 2012

Reversing a String in C

void ReverseString (char *String)
{
char *Begin = String;
char *End = String + strlen(String) - 1;
char TempChar = '\0';
while (Begin < End)
{
TempChar = *Begin;
*Begin = *End;
*End = TempChar;
Begin++;
End--;
}
}

Sorting a Linked List in C

//sorting in descending order
struct node
{
int value;
node* NEXT;
}
//Assume HEAD pointer denotes the first element in the //linked list
// only change the values…don‟t have to change the //pointers
Sort( Node *Head)
{
node* first,second,temp;
first= Head;
while(first!=null)
{
second=first->NEXT;
while(second!=null)
{
if(first->value < second->value)
{
temp = new node();
temp->value=first->value;
first->value=second->value;
second->value=temp->value;
delete temp;
}
second=second->NEXT;
}
first=first->NEXT;
}
}

Reversing a Singly Linked List in C

//
// iterative version
//
Node* ReverseList( Node ** List )
{
Node *temp1 = *List;
Node * temp2 = NULL;
Node * temp3 = NULL;
while ( temp1 )
{
*List = temp1; //set the head to last node
temp2= temp1->pNext; // save the next ptr in temp2
temp1->pNext = temp3; // change next to privous
temp3 = temp1;
temp1 = temp2;
}
return *List;
}

Saturday, 24 November 2012

List of some popular programming languages

C#  (C Sharp) -
Concurrent to java, runs on .NET or compatible platforms (Portable NET, Mono).
It is easier than C++. May share resources with other languages under a common runtime.

C -
C offers great freedom, and lot of debugging challenge thanks to pointers and memory management.

C++ -
C++ is C plus objects, an extended library, templates.

D language -
C++ like language, more dynamic. Compatible with C.

Pascal -
Old language (1970), improved with objects, imposes a strictly structured programming.

Basic ASP -
This very old language (1964) was improved by Microsoft, with a complete programming environment. Other portages exist.

PHP -
Designed to be embedded inside HTML to build dynamic Web pages or update them from databases.

Java -
Was designed to be portable and to replace C++.

JavaScript, ECMAScript -
JavaScript has been invented to build dynamic client-side html pages, ECMAScript is the standardized version.

Python -
A modern interpreted language with powerful built-in features and a unique indentation feature to shorten coding.

Boo -
This is a new version of Python with some new features. It runs on .Net and Mono and thus, no compatibility problem.

ASP -
Scripting language, server-side, for dynamic web pages by Microsoft, same syntax as Basic.

Assembler -
This is near the machine language and the fastest.

Perl -
 A scripting interpreted language. Readabillity and ease of use are not the goal.


Ruby -
Designed with simplicity in mind. It is interpreted, and has a proprietary but extensible library.

Lua -
Add-on or standalone language with extensible semantic.

Cobol -
Business language still used on big computers.

Fortran -
One of the first languages, always used for mathematical tasks.

SQL -
Language of data management. 

XML -
Not really a programming language, but may be used for similar tasks.