SOLUTION :-
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
void printlist(struct node *h){
while(h != NULL){
printf("%d ",h->data);
h = h->next;
}
}
int main(){
struct node *start=NULL;
int a,i;
printf("Enter the no.of Nodes:");
scanf("%d",&a);
for(i=0;i<a;i++){
struct node *newNode = (struct node
*)malloc(sizeof(struct node));
printf("Enter the data:");
scanf("%d",&newNode->data);
newNode->next = NULL;
if(start==NULL)
start =
newNode;
else{
struct node *ptr
= start;
while(ptr->next!=NULL)
ptr = ptr->next;
ptr->next =
newNode;
}
}
printf("Linked List is:\n");
printlist(start);
printf("\nAfter sorting the list is:\n");
struct node *s = start,*st = start;
for(;s!=NULL;s = s->next){
st = start;
for(;st->next!=NULL;st =
st->next){
if(st->data>st->next->data){
int te;
te = st->data;
st->data = st->next->data;
st->next->data = te;
}
}
}
printlist(start);
}
Suppose you have a set of coins of various denominations, with values v1, v2, …, vn....
Making Change: Given coins of denominations (value) 1 = v1 <
v2< … < vn, we wish to make change for an amount A using as
few coins as possible. Assume that vi’s and A are integers. Since
v1= 1 there will always be a solution.
Formally, an algorithm for this problem should take as input:
An array V where V[i] is the value of the coin of the ith
denomination.
A value A which is the amount...
THIS QUESTION MUST BE ANWSERD WITH CLEAR ENGLISH PSEUDOCODE! You have a set of N coins in a bag, each having a value between 1 and M, where M ? N. Some coins may have the same value. You pick two coins (without replacement) and record the sum of their values. Determine(algorithm ) what possible sums can be achieved, in O(M log M ) time. For example, if there are N = 3 coins in the bag with values 1,...
The post office sells stamps of a variety of different denominations (values), and different sizes. Consider a set of n stamps, where each stamp i has a specific denomination di and a size si . All denominations are distinct. All input numbers are positive integers. We can use stamp denominations multiple times. When buying stamps that total to a given postage amount P, we want to minimize the total size of the stamps (to leave the most addressing space on...
Recall that in the "Knapsack Problem", there are n items having respective values V1..n) and weights W1..n), all greater than 0 and one needs to maximize the total value of the subset of the items placed in the knapsack limited by a weight capacity of W In the 0-1 Knapsack Problem, each item must be either be included or excluded in its entirety, in light of the fact that this problem is to be "NP-Complete", how can one solve the...
Recursive backtracking: Suppose I want to burn some songs onto a 650MB CD (some people still do!) and I have a list of song tracks of various sizes. I want to fill up as much of my CD as I can. I can use a recursive backtracking strategy to find a subset of the song tracks that optimally fills my CD (that is, with the least space left unfilled). You should recognise this problem as a version of the Knapsack...
In a Knapsack problem, given n items {I1, I2, · · · , In} with
weight {w1, w2, · · · , wn} and value {v1,v2, ···, vn}, the goal is
to select a combination of items such that the total value V is
maximized and the total weight is less or equal to a given capacity
W .
i-1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using . an...
Please help with question 2 (c).
(2) Suppose, the game is updated so that every item, i, now has weight, wi], in kilograms (you can assume you are passed the item weights in an array, w, of size m). You can only carry n kilograms of weight. (a) (1 point) Example: Let n Ξ 15, m 5. If the item values are v (5.30, 17, 32, 40) and the item weights are w - 2,4, 3,6,15} which should you choose...
this assingent is to pseudocode, i have instructions
and the example my teacher had given me for this, could i have some
assistance, i need to do this in netbeans IDE and i need to use the
scanner method as well and i need to pass both.
Overview: This assignment will allow you to use pseudocode to implement the program to see the value in planning first, coding later. While coding is the glamorous part of the job, software development is...
a=1.3661 and b=1.3483 according to table 2.3
6. (50 pts. Now that you have worked problem 9.46, you should have an understanding of the following problem, which is rather involved but is extremely instructive for understanding phase transitions in particular and equilibrium in general. a. Find the temperature at which N, boils at a pressure of 1 bar assuming N2 is well described by a van der Waals equation. Use the van der Waals constants given in Table 2(16).3. Compare...
The code is in python. The file does not have to be the data
set from HW2. What I need is a code combing selection sort and
merge sort. The 2-1 is what the problem in refers to as Q1.
d) [10 points] Write a code combining both selection sort and mergesort algorithms (NOT insertion and merge sorts) as described in Q1) to find out the most optimal k minimizing time efficiency of your algorithms using 1 M data set...