answersLogoWhite

0


Best Answer

#include "stdio.h"

#include "stdlib.h"

#include "string.h"

#define MAX 50

#define N 2000

void sort_words(char *x[], int y);

void swap(char **, char **);

int main(void)

{

char word[MAX];

char *x[N];

int n = 0;

int i = 0;

for(i = 0; scanf("%s", word) == 1; ++i)

{

if(i >= N)

printf("Limit reached: %d\n", N), exit(1);

x[i] = calloc(strlen(word)+1, sizeof(char));

strcpy(x[i], word);

}

n = i;

sort_words(x, n);

for(i = 0; i < n; ++i)

printf("%s\n", x[i]);

return(0);

}

void sort_words(char *x[], int y)

{

int i = 0;

int j = 0;

for(i = 0; i < y; ++i)

for(j = i + 1; j < y; ++j)

if(strcmp(x[i], x[j]) > 0)

swap(&x[i], &x[j]);

}

void swap(char **p, char **q)

{

char *tmp;

tmp = *p;

*p = *q;

*q = tmp;

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

void main()

{

int i,j,temp1,temp2;

int arr[8]={5,3,0,2,12,1,33,2};

int *ptr;

for(i=0;i<7;i++)

{ for(j=0;j<7-i;j++) {

if(*(arr+j)>*(arr+j+1))

{ ptr=arr+j;

temp1=*ptr++;

temp2=*ptr;

*ptr--=temp1;

*ptr=temp2;

clrscr();

for(i=0;i<8;i++)

printf(" %d",arr[i]);

getch(); }

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>

void sortname(char *name[],int size);

void main()

{

int c=0 ,i;

char *name1[10];

name1[c]=(char*)malloc(10*sizeof(char));

printf("enter the name:::::( ( press end to terminate ) )");

scanf("%s",name1+c);

if(strcmp(name1[c],"end")!=0)

{

c++;

name1[c]=(char*)malloc(10*sizeof(char));

printf("enter the name:::::( ( press end to terminate ) )");

scanf("%s",name1+c);

}

else

{

sortname(name1,c-1);

}

printf("the sorted names are:");

for(i=0;i<c-1;i++)

{

printf("%s",*name1+i);

}

getch();

}

void sortname(char *name[], int size)

{

int j,k;

char temp[10];

for(j=0;j<size-1;j++)

{

for(k=j+1;k<size;j++)

{

if(strcmp(name[j],name[k])>0)

{

strcpy(temp,name[j]);

strcpy (name[j],name[k]);

strcpy(name[k] ,temp);

}

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

This is not a question, but directions. You need to do this.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program that sorts an array of integers using pointers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What will be the program to arrange numbers stored in array in ascending order using pointers?

sorry


Why array is a implicit pointer?

An array of pointers is exactly what it sounds like - one or more pointers arranged in order in memory, accessible through a common base name and indexed as needed. Philosophically, there is no difference between an array of pointers and an array of objects...int a[10]; // 10 integers, named a[0], a[1], a[2], ..., a[9]int *b[10]; // 10 pointers to int, named b[0], b[1], b[2], ..., b[9]If you initialize the array of pointers...int i;for (i = 0; i < 10; i++) b[i] = &a[i];... then *b[0] would be the same as a[0], etc.


What is an array pointers?

I guess it is an 'array of pointers'. Example:int main (int argc, char *argv[])


8086 assembly program to sort a list of integers?

assembly language program for sorting an array using 8086 microprocessor.


How do you write a program that accepts 50 integer values and sort them in basic programming?

Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.


What is Arrays of Pointers?

An array of pointers is a contiguous block of memory that contains pointers to other memory locations. They essentially allow non-contiguous memory locations to be treated as if they were an actual array.


How do you write a C Program to fill up an Integer Array?

Reference:cprogramming-bd.com/c_page1.aspx# array programming


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


How do you write a program in java to read ten numbers and print sum of ten integers?

Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.


What is Jagged Array in C?

A Jagged array is an array of arrays. You can initialize a jagged array as &minus; int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}}; Where, scores is an array of two arrays of integers - scores[0] is an array of 3 integers and scores[1] is an array of 4 integers.


Why would you use the array of pointers to pointers?

You would use an array of pointers to pointers whenever you wished to implement a dynamic multi-dimensional array of 3 or more dimensions. Every multi-dimensional array can ultimately be reduced to a one-dimensional array where each element is itself a one-dimensional array (an array of arrays). With fixed-size arrays, all elements can be allocated contiguously regardless of how many dimensions there are. Fixed size arrays can be allocated both statically (when the size is known at compile time) or dynamically (when the size is unknown at compile time). However with large arrays it is often necessary to divide the array into smaller subarrays each of which is allocated separately (non-contiguously with each other) and maintain a separate array of pointers to keep track of each of those subarrays. Although this consumes more memory than a contiguously-allocated array would, it has the added benefit in that each subarray need not be the same length, thus it can actually save memory overall. However, if we had several such arrays then we would need yet another array in order to keep track of them all, and this array would need to be an array of pointers to pointers.