Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog

Programming Source Codes
C/C++ Source Codes
C# Source Codes
.........More

Aptitude Interview Questions
C/C++ Aptitude Questions
C Aptitude Questions
.........More

Tutorials
C Tutorial
C++ Tutorial
.........More

# C/C++ Source Codes

link list reversal/ to reverse a link list using iteration as well as recursion

this program first generates the singular link list, and can
1.) reverse the linked list using iteration method
2.) reverse the linked list using recursion method
*/

#define null NULL
#include<stdio.h>

//-------------------------------------------------------------
// definition of the node
//-------------------------------------------------------------
int i;
}node;

//-------------------------------------------------------------
//-------------------------------------------------------------
node* create(node* head, int n) {

node* temp, *q;
int i = 0;

temp = (node*)malloc(sizeof(node));
temp->next = null;
temp->i = 0;
}
else { // head is not empty
while(q->next != null)
q = q->next;
}

for(i = n; i < n + 5; i++) {
temp = (node*)malloc(sizeof(node));
temp->next = null;
temp->i = i+1;
q->next = temp;
q = temp;
}

}

//-------------------------------------------------------------
//-------------------------------------------------------------

}

}
//-------------------------------------------------------------
// reverse the link list using the loop (iteration)
//-------------------------------------------------------------
node *curr, *frwd, *rev;
return null;
rev = curr = null;
while (frwd != null) {
rev = curr;
curr = frwd;
frwd = frwd->next;
curr->next = rev;
}
return curr;

}

//-------------------------------------------------------------
// reverse the link list using the recursion
//-------------------------------------------------------------

node* temp = null;
return temp;
}
else
}

node* temp = null;
free(temp);
}
}
//-------------------------------------------------------------
// main fxn
//-------------------------------------------------------------
int main() {

// appending to the link list

// reverse the link list using iterations/ loops
printf("\nlink list after reversion contains: \n");

// reverse the link list by using recursion
printf("\nlink list after reversion contains: \n");

puts("");
return 0;
}

//-------------------------------------------------------------
// End of the Program..
//-------------------------------------------------------------