Nt1330 Unit 3 Assignment 1 Algorithm

170 Words1 Page
Q2.Given an array of n elements that accepts non-repeated items, design an algorithm to sort the array in O(n) time. For example, n=15 Items: 23,67,34,2,5,12,7,43,28,90,58,3,74,50,48. Solution: #include #include typedef struct Node { int data; struct Node * next; } Node; Node * create_node(int val){ Node * temp = (Node *)malloc(sizeof(Node)); if(temp){ temp->data = val; temp->next = NULL; } return temp; } /* This function inserts node at the head of linked list */ void push(Node **headRef, int data){ Node * new_node = (Node *)malloc(sizeof(Node)); new_node->data = data; new_node->next = *headRef; *headRef = new_node; } void printList(Node * head){ while(head){ printf("%d->", head->data); head = head->next;

More about Nt1330 Unit 3 Assignment 1 Algorithm

Open Document