Programming (c++) plz help me ,explain this problem Q.1. (Copying a Linked List
ID: 669297 • Letter: P
Question
Programming (c++)
plz help me ,explain this problem
Q.1. (Copying a Linked List in Reverse Order) Write a program that creates a linked list object of 10 characters and creates a second list object containing a copy of the first list, but in reverse order.
Q.2. The function remove of the class arrayListType removes only the first occurrence of an element. Add the function removeAll to the class arrayListType that would remove all occurrences of a given element. Also, write the definition of the function removeAll and a program to test this function.
Explanation / Answer
1.
public void ReverseLinkedList (LinkedList linkedList)
{
// ------------------------------------------------------------
// Create a new linked list and add all items of given
// linked list to the copy linked list in reverse order
// ------------------------------------------------------------
LinkedList copyList = new LinkedList();
// ------------------------------------------------------------
// Start from the latest node
// ------------------------------------------------------------
LinkedListNode start = linkedList.Tail;
// ------------------------------------------------------------
// Traverse until the first node is found
// ------------------------------------------------------------
while (start != null)
{
// ------------------------------------------------------------
// Add item to the new link list
// ------------------------------------------------------------
copyList.Add (start.Item);
start = start.Previous;
}
linkedList = copyList;
// ------------------------------------------------------------
// That's it!
// ------------------------------------------------------------
}
2.
class ListTypeType
{
public:
void removelAll(int a)
{
int i, arr[]={1,2,3,3,4,5,5,6,3,7};
for(i=0;i<10;i++)
{
if(arr[i]==a)
{
arr[i]=arr[i+1];
}
}
for(i=0;i<10;i++)
{
cout<<arr[i]<<endl;
}
}
};
void main()
{
in n;
cout<<"Enter no";
cin>>n;
removelAll(n);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.