473,503 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program To Sort Graphic Lines

lifeisgreat20009
70 New Member
I want to make a "GRAPHICS PROGRAM" in C language that shows sorting of lines. Something like this:-

------------
-------------------

------

------------------------------------

after sorting the lines should appear as follows on the screen :-

-------
-----------------
---------------------
--------------------------------------

NOTE :- The lines are to be drawn USING LINE() FUNCTION . Also the lines are to be sorted using quick sort algorithm. THESE ARE NOT DASHES, THESE ARE GRAPHICAL LINES SIMILAR TO WHAT WE DRAW IN PAINTBRUSH.

Any help would be greatly appreciated.
Thanks !!!!!


I have tried it but it fails to work . The code is below !!!!!!


Expand|Select|Wrap|Line Numbers
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6. int main(void)
  7. {
  8.    /* request auto detection */
  9.    int gdriver = DETECT, gmode, errorcode;
  10.  
  11.    int x1=50,y1=50,x2=100,y2=50,x3=70,y3=70,x4=150,y4=70;  
  12.    int x5=30,y5=90,x6=50,y6=90,i,l[3],temp,midx,midy;
  13.  
  14.  
  15.  
  16.    /* initialize graphics and local variables */
  17.    initgraph(&gdriver, &gmode, "");
  18.  
  19.    /* read result of initialization */
  20.    errorcode = graphresult();
  21.    /* an error occurred */
  22.    if (errorcode != grOk)
  23.    {
  24.       printf("Graphics error: %s\n", grapherrormsg(errorcode));
  25.       printf("Press any key to halt:");
  26.       getch();
  27.       exit(1);
  28.    }
  29.    midx=getmaxx()/2;
  30.    midy=getmaxy()/2;
  31.    outtextxy(midx-50,10,"UNSORTED LINES");
  32.    outtextxy(midx-50,midy-130,"SORTED LINES");
  33.    line(0,0,getmaxx(),0);
  34.     line(getmaxx(),0,getmaxx(),getmaxy());
  35.     line(getmaxx(),getmaxy(),0,getmaxy());
  36.     line(0,0,0,getmaxy());
  37.  
  38.    setcolor('5');
  39.    line(x1,y1,x2,y2);
  40.    line(x3,y3,x4,y4);
  41.    line(x5,y5,x6,y6);
  42.  
  43.    l[0]=x2-x1;
  44.    l[1]=x4-x3;
  45.    l[2]=x6-x5;
  46.    delay(1000);
  47.    for(i=0;i<=2;i++)
  48.    {
  49.    if(l[i]>l[i+1])
  50.    {
  51.    temp=l[i];
  52.    l[i]=l[i+1];
  53.    l[i+1]=temp;
  54.  
  55.    }  }        delay(1000);
  56.  
  57.    line(x1,y1+110,l[0]+x1,y1+110); delay(1000);
  58.    line(x1,y1+130,l[1]+x1,y1+130);   delay(1000);
  59.    line(x1,y1+150,l[2]+x1,y1+150);
  60.  
  61.  
  62.    getch();
  63.    closegraph();
  64.    return 0;
  65. }
Nov 1 '07 #1
1 1992
sicarie
4,677 Recognized Expert Moderator Specialist
It looks like you have the coordinates of the lines in your program. Why not just compare the x's?
Nov 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
8722
by: vronskij | last post by:
Hi, A C program can be hundreds of thousands lines of code big. C++ millions. How about Python? Suppose , you are a sole programmer (lonewolf). How many lines can one handle? Thanks,
1
5682
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
9
1788
by: Bosconian | last post by:
I'm looking for a method to plot graphic lines and text for a bracket-like display with multiple tiers in a browser. I'm familiar with GD for outputting dynamic graphics, but have never utilized...
23
2347
by: JoeC | last post by:
I am a self taught programmer and I have figured out most syntax but desigining my programs is a challenge. I realize that there are many ways to design a program but what are some good rules to...
0
1862
by: Jvzj017 | last post by:
For this assignment you will write a function which takes as parameters the upper left corner of a button and a string representing the "label" of the button. The function will write the label to the...
6
1561
by: André | last post by:
Hi, I made a webform for a survey, with multiple-choice questions. The results of each question is put into a table e.g.: values frequency 1 6 2 3 3 32 4 ...
11
1978
by: Ground21 | last post by:
Hello. I'm new // sorry for my english :) I have to write simple program i c++. But I don't know how to code src - program should know it's name (unit1.exe so the name is "unit1" or "unit1.exe"...
1
1720
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I want to make a "GRAPHICS PROGRAM" in C language that shows sorting of lines. Something like this:- ------------ ------------------- ------ ------------------------------------ after...
4
5306
by: slapsh0t11 | last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment: Here is my class file...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.