如何以专业的方式编码? [英] How to code in professional manner?

查看:184
本文介绍了如何以专业的方式编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,一个程序如何能够写成一个完美的专业风格。
很多时候,我们写一个非常好的程序/代码,给出准确的输出。一个可能使用最好的算法来解决给定的问题。

I was wondering, how a program can be written in a perfect professional style. Many times it happens that we write a very good program/code which gives the accurate output.One might use the best algorithm to solve the given problem.

但是对于正在阅读代码以供他/她参考的人来说,由于不正确地使用变量/函数名称而变得难以理解代码(以及许多其他问题)

But for a person who is reading your code for his/her reference, it becomes difficult to understand the code because of improper use of variable/function names.(And many other issues)

那么,如何以专业的方式实现写代码的完美?

So how one can achieve this perfection of writing code in professional manner?

您可以通过直接编辑以下代码来阐述您的想法。
(不要编辑问题中的代码)

You can elaborate your thoughts by directly editing the following code. (Don't edit the code in the question :)

您也可以以专业方式重写完整的代码。的帮助。

You can also rewrite the complete code at the end in professional way.Will be a lot of help.

(C中的简单堆排序算法)

(A simple heap sort algorithm in C)

#include<stdio.h>
#include<conio.h>

void insert(int i);
void swap(int *,int *);
void heap_sort(int);

int a[20];

void main()

{

        int n,i;
     clrscr();

     printf("Enter the no of elements : ");
     scanf("%d",&n);
     printf("\nEnter the elements : \n");
     for(i=0;i<n;i++)
     scanf("%d",&a[i]);
     heap_sort(n);
     printf("\nSorted array is : \n");
     for(i=0;i<n;i++)
     printf("\t%d",a[i]);
     getch();
}


void swap(int *p,int *q)
{

     int temp;
     temp=*p;
     *p=*q;
     *q=temp;

}


void heap_sort(int n)
{

     int x=1,i;
     while(x<n)
         {
   for(i=1;i<=n-x;i++)
   insert(i);
   swap(&a[0],&a[n-x]);
   x++;
         }
}



void insert(int i)
{

            int j=(i-1)/2,item=a[i];
     while((i>0) && (item>a[j]))
  {
   a[i]=a[j];
   i=j;
   j=(i-1)/2;
  }
    a[i]=item;

}


推荐答案

阅读代码完成,这是此类主题的最好的书之一。你不会后悔。

Take a read of Code Complete, one of the best books on this type of subject. You won't regret it.

这篇关于如何以专业的方式编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆