Write a program to merge two linked list and find out the running time?
#include<stdio.h>
#include<conio.h>
#define null 0
void create();
void display();
void insert();
void delet();
void erase();
void create2();
void display2();
void insert2();
void delet2();
void erase2();
void link1();
void link2();
void merge();
struct node
{
int info;
struct node *next;
}*start,*ptr,*temp,*prev;
struct node2
{
int info;
struct node2 *nex;
}*start2,*ptr2,*temp2,*prev2;
void main()
{
int op;
clrscr();
do
{
printf("\n1.link1\n2.link2\n3.merge\n4.exit");
printf("\nEnter your option");
scanf("%d",&op);
switch(op)
{
case 1:
link1();
break;
case 2:
link2();
break;
case 3:
merge();
break;
case 4:
break;
default:
printf("\nEnter correct option");
}
}while(op!=4);
getch();
}
void create()
{
int data;
printf("\nEnter the data");
scanf("%d",&data);
do
{
ptr=malloc(sizeof(struct node));
ptr->info=data;
ptr->next=NULL;
if(start==NULL)
start=ptr;
else
{
temp=start;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=ptr;
}
printf("\nEnter the data & Press 0 to terminate");
scanf("%d",&data);
}while(data!=0);
}
void display()
{
temp=start;
if(start==NULL)
printf("\nList is empty");
else
{
printf("\nElements of list:\n");
while(temp->next!=NULL)
{
printf("%d\t",temp->info);
temp=temp->next;
}
printf("%d\t",temp->info);
}
}
void insert()
{
int data,pos;
printf("\nEnter data & position to insert the element");
scanf("d",&data,&pos);
temp=start;
ptr=malloc(sizeof(struct node));
ptr->info=data;
while(temp->next!=NULL)
{
if(temp->info==pos)
{
ptr->next=temp->next;
temp->next=ptr;
break;
}
else
temp=temp->next;
}
if(temp->next==NULL)
{
temp->next=ptr;
ptr->next=NULL;
}
}
void delet()
{
int pos,flag=0;
if(start==NULL)
printf("List is empty");
else
{
printf("Enter element to be deleted");
scanf("%d",&pos);
temp=start;
if(start->info==pos)
{
flag=1;
start=start->next;
free(temp);
}
else
{
while(temp->next!=NULL)
{
prev=temp;
temp=temp->next;
if(temp->info==pos)
{
flag=1;
prev->next=temp->next;
free(temp);
break;
}
}
}
if(flag==0)
printf("\nElement is not present in list");
}
}
void erase()
{
if(start==NULL)
printf("\nList is empty");
else
{
while(start->next!=NULL)
{
temp=start;
start=start->next;
free(temp);
}
temp=start;
start=start->next;
free(temp);
printf("list is erased");
}
}
void create2()
{
int data;
printf("\nEnter the data");
scanf("%d",&data);
do
{
ptr2=malloc(sizeof(struct node2));
ptr2->info=data;
ptr2->nex=NULL;
if(start2==NULL)
start2=ptr2;
else
{
temp2=start2;
while(temp2->nex!=NULL)
{
temp2=temp2->nex;
}
temp2->nex=ptr2;
}
printf("\nEnter the data & Press 0 to terminate");
scanf("%d",&data);
}while(data!=0);
}
void display2()
{
temp2=start2;
if(start2==NULL)
printf("\nList is empty");
else
{
printf("\nElements of list:\n");
while(temp2->nex!=NULL)
{
printf("%d\t",temp2->info);
temp2=temp2->nex;
}
printf("%d\t",temp2->info);
}
}
void insert2()
{
int data,pos;
printf("\nEnter data & position to insert the element");
scanf("d",&data,&pos);
temp2=start2;
ptr2=malloc(sizeof(struct node2));
ptr2->info=data;
while(temp2->nex!=NULL)
{
if(temp2->info==pos)
{
ptr2->nex=temp2->nex;
temp2->nex=ptr2;
break;
}
else
temp2=temp2->nex;
}
if(temp2->nex==NULL)
{
temp2->nex=ptr2;
ptr2->nex=NULL;
}
}
void delet2()
{
int pos,flag=0;
if(start2==NULL)
printf("List is empty");
else
{
printf("Enter element to be deleted");
scanf("%d",&pos);
temp2=start2;
if(start2->info==pos)
{
flag=1;
start2=start2->nex;
free(temp2);
}
else
{
while(temp2->nex!=NULL)
{
prev2=temp2;
temp2=temp2->nex;
if(temp2->info==pos)
{
flag=1;
prev2->nex=temp2->nex;
free(temp2);
break;
}
}
}
if(flag==0)
printf("\nElement is not present in list");
}
}
void erase2()
{
if(start2==NULL)
printf("\nList is empty");
else
{
while(start2->nex!=NULL)
{
temp2=start2;
start2=start2->nex;
free(temp2);
}
temp2=start2;
start2=start2->nex;
free(temp2);
printf("list is erased");
}
}
void link1()
{
int op;
start=NULL;
do
{
printf("\n1.create\n2.display\n3.insert\n4.delete\n5.erase\n6.exit");
printf("\nEnter your option");
scanf("%d",&op);
switch(op)
{
case 1:
create();
break;
case 2:
display();
break;
case 3:
insert();
break;
case 4:
delet();
break;
case 5:
erase();
break;
case 6:
break;
default:
printf("\nEnter correct option");
}
}while(op!=6);
getch();
}
void link2()
{
int op;
start2=NULL;
do
{
printf("\n1.create\n2.display\n3.insert\n4.delete\n5.erase\n6.exit");
printf("\nEnter your option");
scanf("%d",&op);
switch(op)
{
case 1:
create2();
break;
case 2:
display2();
break;
case 3:
insert2();
break;
case 4:
delet2();
break;
case 5:
erase2();
break;
case 6:
break;
default:
printf("\nEnter correct option");
}
}while(op!=6);
getch();
}
void merge()
{
if(start==NULL)
{
start=start2;
}
else
{
temp=start;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=start2;
}
temp=start;
if(start==NULL)
printf("\nList is empty");
else
{
printf("\nElements of list:\n");
while(temp!=NULL)
{
printf("%d\t",temp->info);
temp=temp->next;
}
}
getch();
}
the above listed program is definitely good one, here is a program which just does merging job, http://www.refcode.net/2013/02/merging-linked-lists.html
C sharp dot net example programs for beginers?
using System;
using System.Collections.Generic;
using System.Text;
namespace Average_of_three_Nos
{
class Program
{
static void Main(string[] args)
{
string no1, no2, no3;
int n1, n2, n3;
int average;
Console.WriteLine("Enter First Number");
no1 = Console.ReadLine();
n1 = Int32.Parse(no1);
Console.WriteLine("Enter Second Number");
no2 = Console.ReadLine();
n2 = Int32.Parse(no2);
Console.WriteLine("Enter third Number");
no3 = Console.ReadLine();
n3 = Int32.Parse(no3);
average = (n1 + n2 + n3) / 3;
Console.WriteLine("Average of three Numbers : "+ average);
}
}
}
Program #2:This program will take two positive numbers as its input and then find GCD of them.
using System;
using System.Collections.Generic;
using System.Text;
namespace GCD
{
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
string no1, no2;
int n1, n2;
Console.WriteLine("Enter First Number");
no1 = Console.ReadLine();
n1 = Int32.Parse(no1);
Console.WriteLine("Enter Second Number");
no2 = Console.ReadLine();
n2 = Int32.Parse(no2);
int g=obj.find_gcd(n1, n2);
Console.WriteLine("GCD=" + g);
}
int find_gcd(int a, int b)
{
int c;
if(a
{
c = a;
a = b;
b = c;
}
while(true)
{
c = a%b;
if(c==0)
return b;
a = b;
b = c;
}
}
}
}
Write an algorithm to find the greatest number out of the gioven four numbers?
In C#: int[] list = new int[] { 1 , 2, 3, 4}; int highest = int.MinValue; foreach(int i in list) { if(i > highest) { highest = i; } } Console.WriteLine(highest.ToString() + " is the highest number");
Can you use c plus plus instead of c sharp in aspnet?
No, not directly. But maybe yes indirectly
The code behind languages of a web page in asp.net are either VB.NET or C#.
No, you cannot develop / write codes in C++ in these code-behind
You still can call out to some components written in C++ from these code-behind pages via C# or VB.NET codes
What is the Difference between virtual methods and non virtual methods in c sharp?
A function is a method that returns a value other than void. Methods includes functions, subroutines, constructors, destructors, and properties.
Can anyone 1 pls give a real time example and usage of abstract class and interface in c sharp?
Abstract classes and Interfaces are both examples of contracts with no default implementation. Interfaces are more readily interchangeable between applications (because they can be interpreted as jump tables). Because of this COM in Windows makes heavy usage of interfaces with several master ones being the source of all functionality (e.g., IUnknown).
If a programmer wanted to define a type of thing (e.g., MusicalInstrument), that had certain abilities (e.g. Play) without defining how a MusicalInstrument plays... This could be done with an Interface or an Abstract class.
If the programmer wanted to provide some base functionality to whomever was going to implement this functionality (e.g., Vloume, Output Stream) then this would be more appropriate for an Abstract class.
Abstract classes can even build on interfaces:
public interface IMusicalInstrument
{ void Play(); }
public abstract class MusicalInstrument:IMusicalInstrument
{ private int vol = 10;
public virtual SetVolume(int newVol){vol = newVol;}
public abstract void Play(); }
public class Horn:MusicalInstrument
{ public override void Play(){//* Play something *//} }
Write a program to generate uppercase using cSharp?
string s = "asdfqwer";
s = s.ToUpper(System.Globalization.CultureInfo.CurrentCulture);
Where can you get a Jetbrains ReSharper discount?
The best place to check for Jetbrains discount is the Jetbrains website. The company often offers discounts and specials, especially for the those starting a software business.
What does the 'does not exist in current context' error mean in c sharp?
It means you are trying to modify an entity from outwith the scope of that entity. The following shows an example:
public void button1_Click(object sender, EventArgs e)
{
int x = 42;
timer1.Start();
}
public void timer1_Tick(object sender, EventArgs e)
{
if (x==42) // error: x does not exist in current context
{
// do something...
}
}
Here, the x variable is declared local to the button1_Click event. That is; it is scoped to that function and is only accessible within the context of that function. The timer1_Tick event is a separate function, outwith the scope of the button1_Click event. As such, the timer1_Tick function cannot access x.
In order for both functions to access variable x, that variable must be declared in a scope that is accessible to both functions. Given that both functions are members of the same class, it would make sense to declare x at class scope:
int x = 0;
public void button1_Click(object sender, EventArgs e) {
x = 42;
timer1.Start();
}
public void timer1_Tick(object sender, EventArgs e)
{
if (x==42)
{
// do something...
}
}
Note that the point of declaration defines the scope of the declared entity and that the scope defines the context in which that entity is visible.
How do you unchecked the selected radio button in Visual Studio?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
...
if (radioButton1.Checked == true)
{
radioButton2.Select();
MessageBox.Show("dione");
}
It means Terminate-Stay-Resident. A TSR is a program that remains in memory when the program ends.
What is the code to retrieve data from sql in Net?
at the top
using System.Data.SqlClient;
in the main body (perhaps a click event)
//creates a connection object with a given connection string
SqlDataConnection conn = New SqlDataConnection("connection String");
//creates a command object with the sql and the connection it is to use
SqlCommand cmd = new SqlCommand("SQL String",conn);
//create a data reader to store the data retrieved from the database
SqlDataReader rdr;
//open the connection
conn.Open();
//executes the sql and stores the result in the rdr (Use if there is more than one //cell retrieved from database e.g all records where a value is greater than 0
rdr = cmd.ExecuteReader();
//if there is only one cell retrieved such as only the orderid for a specific order then //use:
variable = cmd.ExecuteScalar();
//then do something with the data WARNING: the connection MUST be open to use the data reader but not with the scalar method
//close the connection
conn.Close();
Hope this helps!
steve
Which situation constructor is used?
Constructor is necessary when you are about to use instance of a class.
Can methods in c sharp declared outside the class?
C# is a completely object-oriented language, everything is an object.
Every datatype, is a superset of the object class.
I'm sorry to say, but every method must be declared inside of a class. :(
What is socket programming in C?
There is nothing called "socket programming in C."
Sockets can be programmed in any programming language. What follows below is a basic idea on how to program sockets.
Socket programming refers to the use of a set of APIs for sending and receiving data over a network. The socket APIs originated on the BSD OS standardized by POSIX and are now found on UNIX, Linux, Windows, and Mac OS.
The concept of a socket is an abstraction for an end point in network communication through which data can be sent to and received from.
The major socket API functions are:
* socket() -- creates a socket of specified type and protocol * bind() -- assigns a local name or address to the socket (in the IP protocol this is usually an IP address and port * connect() -- connects a socket to a remote end point * listen() -- changes the socket's state to listen for incoming connections * accept() -- accepts an incoming connection and returns a new socket for communication over that connection * send() -- send data to remote end point specified with connect() call * sendto() -- in connectionless protocols such as UDP, sends data to a specified remote end point * recv() -- receive data from remote end point (after connection established) * recvfrom() -- receive data from a specified remote end point in connectionless protocol * getsockopt() -- gets current value for a particular socket option
* setsocketoption() -- set value of a particular socket option
How would you define Continue statement?
A continue statement is used to "branch" to the end of a loop without exiting the loop. If we wish to exit the loop entirely, use a break or return statement.
for (int i=1; i<10; ++i) {
if (i==5) continue;
printf (%d ", i);
}
printf ("\n");
The above loop will print the following:
1 2 3 4 6 7 8 9
Dynamic polymorphism is a programming method that makes objects with the same name behave differently in different situations. This type of programming is used to allow Java Scripts to run while playing a game on the computer, for example.
How do you handle error when you click on a link?
If you are referring to handling a link to a page that does not exist, then you can't unless the link was pointing to your application, in which case you can handle it in the Application_Error event in global.asax.
If you are referring to handling a link that causes a postback to your application, and then having an error occur in the Click event, you can trap your logic around a try/catch/finally block. Eg:
protected void Link_Click(object sender, EventArgs e)
{
try
{
// Do something stupid
a = 1/0;
}
catch (Exception ex)
{
ErrorMessage.Text = "Whoops, something went wrong!";
}
}
Why are home row key important?
It is the line of keys that you place your fingers on when typing. This is a way that most people type fastly.