Wednesday, August 6, 2014

Tech Test for ECE-1 RISE , GRAND TEST

GRAND TEST : RVS

1.#include<stdio.h>

int main(){

int no[2][2]={{0},{1,2}};

clrscr();

printf(‘%d’,no[0][0]);

}

a)0 b)nothing c)error d)1

2.#include<stdio.h>

int main()

{

int no[][3]={{0},{1,{2},3}};

clrscr();

printf("%d",no[0][0]);

}

a)error b)nothing c)0 d)3

3.#include<stdio.h>

int main()

{

int i=10;

int no[2][4]={1,0,2};

clrscr();

printf("%d",sizeof(no));

}

a)6 b)8 c)2 d)16

4.#include<stdio.h>

int main()

{

int i=-1;

int no[3][3]={{1,2,3},{4,5,6},{7,8,9}};

clrscr();

for(i++;i<=2;i++)

printf("%d,",0[no[i]]);

}a)1,2,3 b)1,5,9 c)1,4,7 d)

5.#include<stdio.h>

int main()

{

int i=-1;

int no[3][3]={{1,2,3},{4,5,6},{7,8,9}};

clrscr();

for(i++;i<=2;i++)

printf("%d,",1[0[no]]);

}

a)2,2,2 b)4,5,6 c)5,5,5 d)4,4,4

6.

main(){

 char*str=”I love java”;

str=str+3;

printf(“%s”,str);

}

a.i love java b)error c)ove java d)ve java

7.

main(){

char*s[3]={”I love java”,”C++”,”MySQL”};

char**str;

str[0]=s[0];

printf(“%s”,s[0]);

}

a)error b)i love java c)I d)null

8.void main()

{

char *s="\123\n";

printf("%d",sizeof(s));

}

a)4 b)2 c)6 d)error

9.void main()

{

int i;

clrscr();

for(i=1;i<4;i++)

switch(i)

{

switch(i+1)

case 1: printf("%d",i);break;

{

case 2:printf("%d",i);break;

case 3:printf("%d",i);break;

}

switch(i);

}

}

a)23 b)error c)123 d)234

10.

struct student

{

Intsno;

Float fee;

floatwt;

}

main()

{

Structstudent s={100,2000.50};

Printf(“\n%d\t%f\t%f”,s.sno,s.fee,s.wt);

}

a)error b)100 2000.50 0.000000 c)100

2000.50 d)none

11.

union un

{

int no;

char name[20];

};

main()

{

Union un u;

u.no=100;

strcpy(u.name,”xxxx”);

printf(“%d%s”,u.no,u.name);

}

a)100 xxxx b)100 garbage c)error

d)garbage xxxx

12.

Intsquare(int x)

{

return x*x;

}

Which function pointer points statement is

correct to point above function.

a) Int (*fptr)(int) b)int (fptr*)

c)int (fptr)(int*) e)none

13.

typedef char names[20];

which statement is correct

a) Typedef names n; b)names n

c)names:n d)none

14.

update(int*p)

{

*p+=10;

}

main()

{

Int x=10;

update(&x);

printf(“%d”,x);

}

a)10 b)ref error c)20 d)20

15.

struct test

{

Int x;

Int y;

};

main()

{

struct test t[2];

test[0].x=test[0].y=10;

test[1]=test[0];

printf(“%d\t%d”,test[1].x,test[1].y);

}

a)error b)10 10 c)garbage values d)none

16. max2(inta,intb,charch)

{

 }

main()

{

}

a)10 b)20 c)a d)97

17. enum color{RED,GREEN=3,BLUE};

main()

{

struct bfield

{

unsigned type:3;

};

struct bfield b;

b.type=BLUE;

printf("\n%d",b.type);

}a)4 b)3 c)5 d)error

18.# include <stdio.h>

main()

{ char*str="i love java";

char*s;

while(s!=NULL)

{

puts(s);

}

}

a)i love java b)error

c)i d)i

 love

 java

19.

# include <stdio.h>

main()

{

char*str="C_lang";

printf("\n%s",strchr(str,'l'));

}

a)C_ b)l c)lang d)none

20.

# include <stdio.h>

main()

{

char*str="C_lang";

printf("\n%s",memset(str,'x',4));

}

a)ng b)xxxxng c)0000ng d)x0ffng

21. struct a

{ struct b

{

}B;

int x;

};

main()

{

struct a A={100};

A.B.x=A.x=10;

a.x=111;

printf("\n%d",A.B.x);

}

a)100 b)10 c)error d)111

22.

main()

{

const int y=111;

int*x;

x=y;

printf("%d ",*x);

x=&y;

*x+=1;

int x;

printf("%d",*x);

}

a)111 112 b)address 112 c)error d)none

23.

main()

{

struct a

{ int x,y;

}z={10,20};

fun1(z);

}

fun1(struct a B)

{

B.x=100;

printf("%d",B.x);

}

a)100 b)10 c)error d)none

24.

main()

{

char *s[]={"ongole","chennaai","ooty"};

printf("\n%d",*(*(s+2)+1));

}

a)c b)99 c)error d)111

25.

main()

{

char *s1="c";

char*s2="c++";

clrscr();

printf("%c",*s1+*s2-76);

}

a)y b)z c)error d)z

Tech Test for ECE-1 RISE , TEST-3

1#include<stdio.h>

void main()

{

clrscr();

if((2==2) && printf("0") || 0)

printf("true");

else

printf("false");

}

a)true b)0true c)false d)0

----------------------------------------------------------

2.#include<stdio.h>

void main()

{

int ch='\0';

clrscr();

ch++;

while(1 && ch)

printf("%d",ch--);

}

a)NULLb)0 c)1 d)infinate loop

----------------------------------------------------------

3.#include<stdio.h>

void main()

{

int ch=NULL || EOF+1 && EOF ;

clrscr();

printf("%d",ch);

}

a)0 b)1 c)-1 d)48

----------------------------------------------------------

4.#include<stdio.h>

void main()

{ printf("a\/b=c",'%d',"%d");

}

a)a=c b)a\/b=c c)a/b=c

d)error

----------------------------------------------------------

5.#include<stdio.h>

void main()

{ clrscr();

printf("%d",1||-?('\n'==10!=0):printf("ok"));

}

a)1 b)0 c)error d)ok

6.#include<stdio.h>

void main()

{

float x=10.2345F;

int a;

clrscr();

a=x-(int)x;

printf("\n%f",(float)a);

}

a)10.234500 b)0.000000

c)error d)10.2345

7.#include<stdio.h>

void main()

{

clrscr();

printf("a%cb",'\\b');

}

a)a\b b)a\\b c)b d)error

8.#include<stdio.h>

void main()

{

float f=2.0;

clrscr();

printf("%d\t\t%d",a,sizeof(2.0f+2));

}

a)4 b)8 c)6 d)error

----------------------------------------------------------

9. #include<stdio.h>

void main()

{

char ch='ab';

clrscr();

do

{

}while(ch!='c'+1);}

a)abc b)ab b)abcd d)error

10. #include<stdio.h>

void main()

{

int i,no=0;

clrscr();

for(i=0;i<=5;no+=i++,i==5?

printf("%d",no):0);

}

a)15 b)10 c)100 d)150

11. #include<stdio.h>

void main()

{char ch='0a';

switch(ch)

{

case '0a':

16. #include <stdio.h>

 int main()

{

int i=10,j=9;

clrscr();

puts("\nfirst"); break;

case 48:

puts("\nsecond");break;

default:printf("wrong");

}

}

a)first b)wrong c)error d)second

12. #include<stdio.h>

void main()

{

int a=5^8;

printf("%d",a*a);

}

a)13 b)169 c)-169 d)-13

13. #include <stdio.h>

 int main()

 { int i = 0, j = 0;

 while (i < 5, j < 10)

 {

 i++; j++;

 }

 printf("%d, %d\n", i, j);

 }

a)0,0 b)5,5 c)10,10 d)error

14. #include <stdio.h>

 int main()

{ int a=7,b=2;

printf("\n%d",(int)((float)a/b-(int)a/b));

 }

a)0.5 b)0 c)0.500000 d)error

15. #include <stdio.h>

 int main() {

 }

a)1 19 b)0 18 c)1 10 d)1 19

17. #include <stdio.h>

 int main()

{

int a = 6;

int b = 12;

clrscr();

while(a<b){

printf("\n%d %d",a,b,a+=2,b-=2);

}

 }

How many loops took in the above program

a)1 b)2 c)3 d)0

18. #include <stdio.h>

 int main()

{ do

 }

a)a\bc b)c c)a\b d)error

if(1)

if(0);

else if(1)

printf("\nOver");

else;

 }

a)Over b)syntax missing error c)nothing d)

misplaced else

19.write a program to print

54321012345 (use only one for)

20. print

0

1 0

0 1 0

1 0 1 0

0 1 0 1 0

Tech Test for ECE-1 RISE , TEST-2

#include<stdio.h>

void main()

{

clrscr();

if((2==2) && printf("0") || 0)

printf("true");

else

printf("false");

}

a)true b)0true c)false d)0

-----------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

void main()

{

int ch='\0';

clrscr();

ch++;

while(1 && ch)

printf("%d",ch--);

}

a)NULLb)0 c)1 d)infinate loop

-----------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

void main()

{

int ch=NULL || EOF+1 && EOF ;

clrscr();

printf("%d",ch);

}

a)0 b)1 c)-1 d)48

----------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

void main()

{

printf("a\/b=c",'%d',"%d");

}

a)a=c b)a\/b=c c)a/b=c d)error

---------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

void main()

{

clrscr();

printf("%d",1||-1?('\n'==10!=0):printf("ok"));

}

a)1 b)0 c)error d)ok

#include<stdio.h>

void main()

{

float x=10.2345F;

int a;

clrscr();

a=x-(int)x;

printf("\n%f",(float)a);

}

a)10.234500 b)0.000000 c)error d)10.2345

#include<stdio.h>

void main()

{

clrscr();

printf("a%cb",'\\b');

}

a)a\b b)a\\b c)b d)error

#include<stdio.h>

void main()

{

float f=2.0;

clrscr();

printf("%d\t\t%d",a,sizeof(2.0f+2));

}

a)4 b)8 c)6 d)error

Tech Test for ECE-1 RISE , TEST-1

1.Which of the following is not a valid variable name declaration?

a) int __a3;

b) int __3a;

c) int __A3;

d) None of the mentioned

2. C99 standard guarantess uniqueness of _____ characters for external names.

a) 31

b) 6

c) 12

d) 14

3What is the output of this C code?

• #include <stdio.h>

• int main()

• {

• char chr;

• chr = 128;

• printf("%d\n", chr);

• return 0;

• }

a) 128

b) -128

c) Depends on the compiler

d) None of the mentioned

Answer:b

Explanation:signed char will be a negative number.

4. #include <stdio.h>

 int main()

 {

 enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};

 printf("PEACH = %d\n", PEACH);

 }

a) PEACH = 3

b) PEACH = 4

c) PEACH = 5

d) PEACH = 6

5. # define X(a,b,c) a>b&&a>c?a:b>c?b:c; this macro is used to perform _____________________

6. char ch=’97’ the value of ch is ______________

7. #include <stdio.h>

 int main()

 {

 int i = 3;

 int l = i / -2;

 int k = i % -2;

 printf("%d %d\n", l, k);

 return 0;

 }

-1 , 1

8. Evaluate int x = 5 * 9 / 3 + 9;

24

• Evaluate 4*8/2+3*2/2

(19)

10. int n1=10;

 Int n2=n1+++++n1+--n1;

What is the value of n2? ________________________

11. #include <stdio.h>

 void main()

 {

 int x = 1, y = 0, z = 5;

 int a = x && y || z++;

 printf("%d", z);

 }

What it produces out put6

12. • int x = 1, y = 0, z = 3;

• x > y ? printf("%d", z) : return z;

 What is the out put ________________

13. #include <stdio.h>

 int main()

 {

 int i = 0, j = 0;

 if (i && (j = i + 10))

 //do something

 ;

 }

0

14.

int i = 0, j = 0;

if (i && (j = i + 10))

//do something

;

The value of j is 0

15.

int a = 1, b = 1, d = 1;

printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++);

o/p is 15,4,5

16. int a = !0;

printf("\n.....%d",a);

ans : 1

Monday, December 30, 2013

Linked Lists Notes

Linked Lists
*Sequential method of allocation is suitable for certain applications only.
*Other applications where the sequential allocation method is unacceptable usually has the following characteristics.
1. unpredictable storage requirements:- The exact amount of data storage required by program in these areas often depends on the particular data being processed and consequently ,this requirement cannot be easily determined at the time the program is written.
2. Extensive manipulation of the stored data:- programs in these areas typically require that operations such as insertions and deletions be performed frequently on the data.
The linked-allocation method of storage can be result in both the efficient use of computer storage and computer time.
The use of pointers or links to refer to elements of a data structure (which is linearly ordered) implies that elements which are logically adjacent need not be physically adjacent in memory. This type of allocation is called Linked Allocation.
A list has been defined to consist of an ordered set of elements which may vary in number. A simple way to represent a linear list is to expand each node to contain a link or pointer to the next node. This representation is called a one-way chain or singly linked linear list.
Representation:
*List with array implementation requires O(n) time for insertion and deletion operations.
*Linked list implementation of list requires O(1) time for insert/delete operations.
Disadv:
If the position of an element is given in the list it requires O(n) time to find in linked list.
Single Linked List:
*If we want to delete an element from a single linked list we need the address of its previous node.
*We can only insert the new element after a given node.
Insertion into single linked list:
Deletion from a linked list
A special node (dummy node) called as header node is used in the beginning of the list, which is used to maintain the information about the list like, no elements, type of the
elements, owner of the list etc.
Header node facilitates us to insert in the front of the list, as eliminating the special case of deleting first node.
Single Linked list :Implementation
typedef struct node *nptr;
struct node
{
int data;
Data next
nptr next;
};
*Creating the list
nptr Createhead(void)
{ /*Creating the header node */
nptr L;
L = (nptr)malloc (sizeof(struct node));
if (L = = NULL)
printf(“out of space”);
else
L ->next = NULL
return(L);
}
*Counting the no of nodes of the list
int countnodes(nptr L)
{ /*Counting the no of nodes */
int k =0;
nptr p;
p = L -> next
while(p! = NULL)
{
k++;
p = p-> next;
}
return(k);
}
*printing the list
void printlist(nptr L)
{ /*Printing the list */
nptr p;
p = L ->next;
while (p!=NULL)
{
printf(“%d”, p->data);
p = p-> next;
}
}
*Finding previous of the given element(delete)
nptr findprev(nptr L, int x)
{/*Finding the previous of given node */
nptr p;
p = L;
while ((p->next!=NULL) && (p->next ->data!= x)
{
p = p->next;
}
return(p);
}
The above function returns last node address when x does not exist.
X =25
*Finding the address of a node after which the new element is to be inserted.
nptr findpos (nptr L ,int x)
{/*Finding the position of the given node */
nptr p;
p = L;
while ((p->next!= NULL) &&(p->next ->data < x))
p = p-> next;
return(p);
}
*Finding the address of the last node
nptr findlast (nptr L)
{/*Finding the address of last node */
nptr p;
p = L;
while(p->next != NULL)
p = p->next;
return(p);
}
*Inserting an element into an ordered list
void ordinsert(nptr L,int x)
{/*Inserting the element into a ordered list */
nptr temp p;
p = findpos(L,x)
temp = (nptr) malloc (sizeof(struct node));
if (temp = = NULL)
printf(“out of space”);
else
{
temp ->data = x;
temp ->.next = p->next;
p->next = temp;
}
}
*Inserting an element in the beginning of the list
void beginsert (nptr L,int x)
{/*Inserting the element at the beginning */
nptr temp;
temp = (nptr) malloc (sizeof (struct node));
if(temp!= NULL)
{
temp ->data = x;
temp -> next = L -> next;
L-> next = temp;
}
else
printf(“out of space”);
}
*Inserting an element at the end of the list
void endinsert (nptr L,int x)
{ /*Inserting the element at the end */
nptr temp,last;
last = findlast(L);
temp = (nptr)malloc(sizeof(struct node));
if(temp = = =NULL)
printf(“out of space”);
else
{
temp ->data = x;
temp ->next = last->next;
last-> next = temp;
}
}
*Creating an ordered list
nptr Createlist(void)
{/*Creating an ordered list*/
nptr L;
int x;
L = Createhead();
while(1)
{
printf(“Enter the element –999 at the end”);
scanf(“%d”, &x);
if(x = = - 999)
break;
else
ordinsert(L,x);
}
return(L);
}
*Deleting an element x from the given list
void delete (nptr L,int x)
{/*Deleting an element x from the given list */
nptr temp,prev;
prev = findprev(L,x);
if (prev-> next ! = NULL)
{
temp = prev -> next;
prev->next = temp-> next;
free(temp);
}
else
printf(“Element is not existing”);
}
*updating an element of a given SLL
void update(nptr L,int x,int y)
{
nptr p;
p = find(L,x);
if(p = = NULL)
printf (“Element is not existing”);
else
p->data = y;
}
*Appending two lists
nptr append(nptr L1,nptr L2)
{
nptr last;
if(L1 -> next = = NULL)
return(L2);
else if(L2 ->next = = NULL)
return(L1)
else
{
last = findlast(L1)
last->next =L2->next;
free(L2);
return(L1)
}
*splitting a given list into two lists based on the given value of ‘x’.
nptr split(nptr L1,int x)
{
nptr p,L2;
L2 =createhead();
p = find(L1,x);
L2 -> next = p ->next;
p->next = NULL;
return(L2);
}
*Merging two linked lists
nptr merge (nptr L1,nptr L2)
{
nptr L3, t1,t2,t3,temp;
L3 =createhead();
t1 = L1 -> next;
t2 = L2-> next;
t3 = L3;
while((t1! = NULL) && (t2! = NULL))
{
temp = (nptr)malloc(sizeof(struct node));
t3->next = temp;
t3 =temp;
if( t1 ->data <= t2->data)
{
temp -> data = t1->data;
t1 = t1->next;
}
else
{
temp->data = t2->data;
t2 = t2->next;
}
}
while (t1!= NULL)
{
temp = (nptr) malloc (sizeof(struct node ));
t3->next = temp;
t3 =temp;
temp->data = t1->data;
t1 = t1->next;
}
while (t2!= NULL)
{
temp = (nptr)malloc(sizeof(struct node ));
temp->data = t2->data;
t2 =t2->next;
t3->next = temp;
t3 = temp;
}
t3->next = NULL;
return (L3);
}
*Merging two lists without using any extra memory
nptr merge (nptr L1,nptr L2)
{
nptr t1,t2,t3;
t1 = L1->next;
t2 =L2 -> next;
while ((t1!= NULL) && (t2!=NULL)
{
if (t1->data <= t2->data)
{
t3 ->next = t1;
t1 = t1->next;
}
else
. {
t3-> next = t2;
t2 = t2 -> next;
}
t3 = t3->next;
}
if (t1= = NULL)
t3->next = t2;
else
t3->next = t1;
free(L2);
return(L1);
}
*Reversing a given SLL
L P q r
void reverse(nptr L)
{
nptr p,q,r;
p = NULL;
q = L -> next;
while (q!= NULL)
{
r = q ->next;
q->next = p;
p = q;
q = r;
}
L->next = p;
}
Polynomial Implementation:
One variable polynomials can be implemented using arrays
ex : 8x6 + 5x 4 + 3x 3 + 6x + 5
Each term of the polynomial consists of two values size: Coef. and xpower. In the array they can be represented using the value and position.
9 8 7 6 5 4 3 2 1 0
0
0
0
8
0
5
2
0
6
5
*Functions for polynomial Addition
A function which can read the polynomial and return the highest degree (user enters c,e; 0, 0 at the end)
int readpoly(int p [])
{
int hd.,c,e,i;
for (i = 0;i< size;i++)
p[i] = 0;
while (1)
{
printf(“Enter coef & xpower”);
scanf(“%d %d” ,&c ,&e);
if(c= = 0)
return(hd);
else
{
p[e] = c;
if(hd < e)
hd = e;
}
}
}
*printing a polynomial when the highest degree is given
void printpoly(int p[], int hd)
{
int i;
for(i = hd;i>0 ; i++)
{
if(p[i] ! = 0)
{
printf(“+(%d) x ^ %d” ,p [i] , i): } } printf(“+(%d)”,p[i]);
}
*Adding two polynomials is adding two arrays
*Disadvantage with array representation is wastage of memory.
Polynomials can be implemented using an array of structures.
ex: 10 x7 + 5x 5 + 3x 4 + 4x
0 1 2 3 4 5 6
10
5
3
4
7
5
4
1
Implementation
struct term
{
int coef;
int exp;
};
typedef struct term sterm;
*Function to read the polynomial & returns no of terms.
int readpoly(sterm p[])
{
int i;
i = 0;
do
{
printf(“Enter the coef & xpower”);
scanf(“%d %d”, & p[i].coef , &p[i].xp);
i++;
}
while(p[i-1].coef != 0);
return(i-1);
}
*printing a polynomial when the no of terms is known
void printpoly(stem p[] ,int n)
{
int i;
for( i = n-1 ; i>= 0;i--)
{
if(p[i].xp = = 0)
break;
else
printf(“+(%d) x^%d”, p[i].coef,p[i] .xp);
}
if(i > = 0)
printf(“ + (%d)”, p[i].coef );
}
Adding two polynomials
m-1
P1
10
8
3
4
2 6 5 2 1 0
n-1
P2 2 4 4 1 4
4
4
3
2
0
10
6
P3
int polynomialadd( sterm p1[ ] , sterm p2[ ], sterm p3[] ,int m,int n)
{
int i,j ,k;
i = j= k =0
while( ( i< m) &&( j < n))
{
if( p1[i] .xp = = p2[j].xp)
{
p3[k].coef = p1[i] .coef + p2[j].coef;
p3[k].xp = p1[i] .xp;
k++;i++;j++;
}
else if(p1[i].xp > p2[j].xp)
{
p3[k].coef = p1[i].coef;
p3[k].xp = p1[i].xp;
i++;k++;
}
else
{
p3[k].coef = p2[1].coef;
p3[k].xp = p2[j].xp;
j++; k++;
}
}
while(i < m)
{
P3[k] = p2[j];
k++;j++;
}
while(j<n)
{
P3[k] = p2[j];
k++;j++;
}
return(k);
}
Linked list Implementation of polynomials
typedef struct tnode * tnptr;;
Struct tnode
{
int coef; coef xp
next
int xp; term
tnptr next;
};
*Function to find the address of the term with the power e.
tnptr findterm(tnptr p, int e)
{
tnptr t;
t = p -> next;
while(( t! = NULL) && ( t ->xp ! = e))
t = t->next;
return(t);
}
*Function to find the address of a node after which the new term is to be inserted.
tnptr findtpos(tnptr p ,int e)
{
tnptr t;
t =p;
while((t->next ! = NULL) &&(t->next ->xp >e))
t = t->next;
return(t);
}
*Function to insert a term into the polynomial void terminsert (tnptr p,int c,int e)
{
tnptr pos temp;
pos = findterm(p,e);
if (pos ! = NULL)
pos ->coef + = c;
else
{
pos = findtpos(p,e);
temp = (tnptr)malloc(sizeof(struct tnode));
temp ->coef = c;
temp ->xp = e;
temp ->next = pos->next;
pos->next = temp;
}
}
*Multiplying two polynomials
tnptr polyprod(tnptr p1, tnptr p2)
{
tnptr t1,t2,p3;
int c,e;
p3 = createhead();
for( t1 = p1->next ;t1! = NULL;t1 = t1->next)
for(t2 = p2->next;t2!= NULL;t2 = t2->next)
{
c = t1->coef * t2 ->coef;
e = t1->xp + t2->xp;
terminsert(p3,c,e);
}
return(p3);
}
*Function to add two polynomials
tnptr polyadd(tnptr p1,tnptr p2)
{
tnptr t1, t2,t3,p3,temp;
p3 = createhead();
t1 = p1->next;
t2 = p2->next;
t3 = p3;
while((t1! = NULL) && (t2 != NULL)
{
temp = (tnptr)malloc (sizeof(struct tnode));
t3 ->next = temp;
t3 = temp;
if(t1 ->xp > t2 ->xp)
{
t3 ->coef = t1 ->coef;
t3 -> xp = t1->xp;
t1 = t1->next;
}
else if(t1->xp < t2->xp)
{
t3 ->coef = t2->coef;
t3 ->xp = t2 ->xp;
t2 = t2->next;
}
else
{
t3 ->coef = t1->coef + t2->coef;
t3 ->xp = t1->xp;
t1 = t1->next;
t2 = t2 ->next;
}
}
while(t1!= NULL)
{
temp = (tnptr)malloc(sizeof(struct tnode));
temp -> coef = t1 ->coef;
temp-> xp = t1->xp;
t1 = t1->next;
t3 ->next = temp;
t3 = temp;
}
while (t2 != NULL)
{
temp =(tnptr) malloc (sizeof(struct tnode));
temp ->coef =t2->coef;
temp-> xp = t2 ->xp;
t2 = t2->next;
t3 -> next = temp;
t3 = temp ;
}
t3 -> next = NULL;
return(p3);
}
Circular Linked List(CLL)
Last node next field will give the address of the first node/header node
*If the address of any node is given we can access all the nodes, which is not possible in SLL.
*Function to reverse the elements/nodes of CLL.
void reversecll(nptr L)
{
nptr p,q,r;
p =L;
q= L->next;
while(q! = L)
{
r = q->next;
q->next = p;
p->q;
q-> r;
}
L->next = p;
}
*Function to concatenate two CLLs
nptr concat(nptr L1,nptr L2)
{
nptr p;
p = L1->next->next;
L1->next ->next = L2->next->next;
L2->next ->next = p;
free(L1);
return(L2);
}
Double Linked List
Each node gives the addresses of its previous node and its next node-two links are maintained.
If the address of a node is given we can delete it which is not the case with SLL.
If the address of a node is given we can insert a new element before it or after it.
If one link is lost, we can restore it using the other link.
We can traverse list in both the directions.
dnode
prev
data
next
typedef struct dnode* dnptr;
struct dnode
{
dnptr prev;
int data;
dnptr next;
};
Representation :
*Function to delete a given element from DLL
void delete(dnptr H, int x)
{
dnptr p;
p=find(H,x);
if (p = = NULL)
printf(“Element is not existing”);
else
{
if(H->prev = = H->next)
{
H->prev = H->next = NULL;
}
else if(p = = H->prev)
{
H->prev = p->next;
p->next ->prev = NULL;
}
else if(p = = H->next)
{
H->next = p->prev;
p->prev ->next = NULL;
}
else
{
p->next ->prev = p->prev;
p->prev ->next = p->next;
}
free(p);
}
}
* Function to insert an element into DLL before given node ‘p’.
void dllinsertbp(dnptr H,dnptr p,int x)
{
dnptr temp;
temp = (dnptr)malloc(sizeof(struct dnode));
temp ->data = x;
if(p->NULL)
{
temp ->prev = temp ->next = NULL;
H->prev = H->next = temp;
}
else
if (p = =H->prev)
{
temp ->next = p;
temp->prev = NULL;
p->next = temp;
H->prev = temp;
}
else
{
temp ->next = p;
temp ->prev = p->prev;
p->prev ->next = temp;
p->prev = temp;
}
}
Radix Sort:- Function ‘m’ –is the no of digits.
void radixsort(nptr L,int m)
{
nptr B[10],T[10],p,q,prev;
int i,j ,k d;
for(i =0; i<=m;i++)
{
/* intializing the buckets*/
for(j=0;j<= 9;j++)
B[j ] = T[j ] = NULL;
p = L->next;
/* Distributing the elements into buckets based on a digit*/
while(p!=NULL)
{
q = p->next
d= p->data/pow(10,j)%10;
if(T[d] = = NULL)
T[d] = B[d] = p;
else
{
T[d] ->next = p;
T[d] =p;
}
T[d] ->next = NULL;
p = q;
}
/* Combining all the buckets.*/
k = 0;
while(B[k ] = = NULL)
k++;
L->next = B[k] ;
for(j = k+1; j<= 9; j++)
{
prev = T[j-1];
if(B[j]!=NULL)
prev -> next = B[j];
else
T[j] = prev;
}
}
}
Time Complexity : T(n) = O(m * n).

Saturday, October 20, 2012

Expected Dates for NP Lab Practical Examinations

Expected dates for NP-Lab practical external examinations  on or after 25th oct'12.
NOTE : Dates r tentative ,u must confirm the dates.
 

Wednesday, October 10, 2012

Imp Q's for MID-2 Examination for Final B.Tech , Sub : NP


Expected q's
1)    a) Write a sample to discuss lack of flow control in UDP.
b) Discuss about recvfrm(),sendto(),read() functions.
2)  a) Discuss types of resource records.
      b) Discuss about resolver functions.
3)  Explain with diagrams for the following I/O multiplexing  
      models
              i) Blocking.
               ii) Non-blocking.
              iii) Signal driven.
4) Explain the role of resolver with neat diagram that depict the management of application, resolver and name server.
5) a) discuss about functionalities of select and poll functions
     b) discuss about resolver options RSE_USE_INIT6.