Insertion Sort in C

#include <string.h>
#include <stdio.h>
#include <stdlib.h>


void insert(char *items, int count) {

  register int i, b;
  char t;

  for(i=1; i < count; ++i) {
    t = items[i];
    for(b=i-1; (b >= 0) && (t < items[b]); b--)
      items[b+1] = items[b];
   // items[b+1] = t;
    items[b] = t;
  }
}

int main(void)
{
  char s[255] = "asdfasdfasdfadsfadsf";
  insert(s, strlen(s));
  printf("The sorted string is: %s.\n", s);

  return 0;
}

Comments

Popular posts from this blog

Error : DependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.adobe.aem:uber-jar:jar:apis -> version 6.3.0 vs 6.4.0

Operators in Asterisk with Linux

ERROR Exception while handling event Sitecore.Eventing.Remote.PublishEndRemoteEventException: System.AggregateExceptionMessage: One or more exceptions occurred while processing the subscribers to the 'publish:end:remote'